title: IOS - UIImagePickerController - Constrain the proportions of an image
body: <p>I have setup a simple photo capture system to capture a profile pic within an IOS app, all works fine apart from I dont understand how to constrain the proportions of the image to suit the 120px x 120px profile image frame.</p>
  
  <p>Can anyone offer any suggestions?</p>
  
  <p>The UIview looks as follows - 
  <img src="https://i.stack.imgur.com/t09Zw.png" alt="enter image description here"></p>
  
  <p>My code is as follows - </p>
  
  <pre><code>- (IBAction)takePhoto:(id)sender {
       if ([UIImagePickerController isSourceTypeAvailable:
       UIImagePickerControllerSourceTypeCamera])
      {
      UIImagePickerController *imagePicker =
      [[UIImagePickerController alloc] init];
      imagePicker.delegate = self;
      imagePicker.sourceType =
      UIImagePickerControllerSourceTypeCamera;
      imagePicker.mediaTypes = @[(NSString *) kUTTypeImage];
      imagePicker.allowsEditing = NO;
      [self presentViewController:imagePicker
                         animated:YES completion:nil];
      _newMedia = YES;
     }
  
  
  }
  
  - (IBAction)editPicBtn:(id)sender {
      [_cameraPanel setHidden:NO];
  
  
   }
  
   -(void)imagePickerController:(UIImagePickerController *)picker
   didFinishPickingMediaWithInfo:(NSDictionary *)info
  {
      NSString *mediaType = info[UIImagePickerControllerMediaType];
  
       [self dismissViewControllerAnimated:YES completion:nil];
  
      if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
      UIImage *image = info[UIImagePickerControllerOriginalImage];
  
      _photoSquare.image = image;
  
      if (_newMedia)
          UIImageWriteToSavedPhotosAlbum(image,
                                         self,
  
                                                 @selector(image:finishedSavingWithError:contextInfo:),
                                         nil);
  }
  else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
  {
      // Code here to support video if enabled
  }
  [_cameraPanel setHidden:YES];
  
  }
  
  -(void)image:(UIImage *)image
   finishedSavingWithError:(NSError *)error
   contextInfo:(void *)contextInfo
  {
      if (error) {
        UIAlertView *alert = [[UIAlertView alloc]
                            initWithTitle: @"Save failed"
                            message: @"Failed to save image"
                            delegate: nil
                            cancelButtonTitle:@"OK"
                            otherButtonTitles:nil];
        [alert show];
   }
  }
  
   -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
   {
       [self dismissViewControllerAnimated:YES completion:nil];
   }
  
  - (IBAction)useCameraRoll:(id)sender {
     if ([UIImagePickerController isSourceTypeAvailable:
       UIImagePickerControllerSourceTypeSavedPhotosAlbum])
     {
      UIImagePickerController *imagePicker =
      [[UIImagePickerController alloc] init];
      imagePicker.delegate = self;
      imagePicker.sourceType =
      UIImagePickerControllerSourceTypePhotoLibrary;
      imagePicker.mediaTypes = @[(NSString *) kUTTypeImage];
      imagePicker.allowsEditing = NO;
      [self presentViewController:imagePicker
                         animated:YES completion:nil];
      _newMedia = NO;
      }
  
  
  
  }
  </code></pre>