3
votes

I have an UIImage (dimension 320x480) that I want to display with a much smaller UIImageView (dimension: 100x100).

But when I add the image, it bleeds through the UIImageView and its superviews. How can I restrict the rendering of the image so it is only shown within the bounds of the UIImageView and centered with respect to the UIImageView's center?

View hierarchy is as follows:

view: (main view associated with UIViewController)
 -level_1 view (contentMode = UIViewContentModeScaleToFill)
 --level_2 view (contentMode = UIViewContentModeCenter)
 ---level_3 view (container for UIImageView, contentMode = UIViewContentModeCenter)
 -----UIImageView (contentMode = UIViewContentModeCenter)

level_3 view size: 100x100 image size: 320x480

2

2 Answers

8
votes

set the clipsToBounds property on the UIImageView to YES

7
votes

Have you tried -setClipsToBounds:YES ?