Reputation: 42139
I have a bunch of UIImageViews that are in different proportions. Some of 100x101 some are 130x121.
How can I mask these to 80x80 and NOT stretch the images? I basically just want to mask a square out of each one. (kind of like the Apple's Photo thumbnail view does)
Upvotes: 1
Views: 1761
Reputation: 6066
Set its content mode UIViewContentMode, you may be looking for UIViewContentModeScaleAspectFit
or UIViewContentModeScaleAspectFill
.
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 80, 80)];
[imageView setContentMode:UIViewContentModeScaleAspectFit];
[imageView setImage:[UIImage imageNamed:@"myImage.png"];
.
.
.
Upvotes: 0
Reputation: 6448
Finally, to make round corners, use the following code, and import QuartzCore/QuartzCore.h at the beginning of your implementation file.
CALayer * layer = [myImageView layer];
[layer setMasksToBounds:YES];
[layer setCornerRadius:12.0f];
Edited: Yes, by saying size I mean frame, the W and H:
Upvotes: 5