I need to crop a UIImage
, taken with the device camera, so that it fits inside another UIImage
, which represents a frame
(with rounded
In interface Builder, access the Mode menu inside of the detail pane (the fourth one) and choose the right one for your UIImageView
(I guess "center" or "aspect fit").
OLD ANSWER:
You can use the contentGravity property of CALayer to make it work
A constant that specifies how the layer's contents are positioned or scaled within its bounds.
@property(copy) NSString *contentsGravity
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.
Use an UIImageView
and do
imageView.contentMode = UIViewContentModeScaleAspectFit;
make a IBOutlet
in your controller.
@property (retain)IBOutlet UIImageView* imageView;
and in -(void) viewDidLoad
set
imageView.layer.masksToBounds = YES;