I have an image that I would like to display in a UITableViewCell
using the UITableViewCellStyleSubtitle
style that provides a UIImageView
, and two lines of text, plus an optional accessory view.
However, when I set the content mode of the UIImageView
to either of UIViewContentModeScaleAspectFit
or UIViewContentModeScaleAspectFill
, it appears to make no difference. Both of these content modes simply display the entire image, shifting the text to the right to make room for the image.
Does anyone have any examples of how these actually differ in practice? The docs say:
UIViewContentModeScaleAspectFit:
Scales the content to fit the size of the view by maintaining the aspect ratio. Any remaining area of the view’s bounds is transparent.
UIViewContentModeScaleAspectFill:
Scales the content to fill the size of the view. Some portion of the content may be clipped to fill the view’s bounds.
But these content modes don't appear to be behaving as advertised.
EDIT: I'm running SDK iOS 4.
I had the same problem. Seems like the Apple documentation is a bit lacking.
I found the answer by searching around the internet. http://www.iphonedevsdk.com/forum/iphone-sdk-development/2973-crop-image.html
Basically,
img1.contentMode = UIViewContentModeScaleAspectFill;
img1.clipsToBounds = YES;
If you want it to be a bit more fancy, check out this post: UIImageView change Width and Height