I need to crop a UIImage
, taken with the device camera, so that it fits inside another UIImage
, which represents a frame
(with rounded borders and so on). Check the image below:
Using Aspect Fill
Using Aspect Fit
So, what I need is to remove the image excess that is out of the frame bounds. I tried using UIBezierPath
, CGImageRef
and other methods that I Googled but I'm not finding a solution for this.
In Interface Builder, use the following configuration:
There are two important settings, namely:
Mode: Aspect Fill
Clip Subviews
It can also be done programmatically:
[imageView setContentMode:UIViewContentModeScaleAspectFill]; [imageView setClipsToBounds:YES];
This will correctly fill the view with the image, keep its aspect ratio and hide what doesn't fit.
make a IBOutlet
in your controller.
@property (retain)IBOutlet UIImageView* imageView;
and in -(void) viewDidLoad
set
imageView.layer.masksToBounds = YES;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With