PDA

View Full Version : Resizing images in UIImageView




ace2600
Jul 1, 2008, 11:29 PM
Hi,

Is there a way to proportionally resize the image in the UIImageView? UIImageView automatically stretches the image to fill its frame, but I want it streteched proportionally (may have black bars on either top/bottom or left/right).

The only idea I had was to change the UIImageView's frame, but this is not desirable as keeping the width fixed is important (there will be several UIImageViews laid out next to eachother and calculations will be done based on the widths, like the page control sample code).



kpua
Jul 2, 2008, 01:45 AM
I'm not sure, but I believe what you want is view.contentMode = UIViewContentModeScaleAspectFit.

I was confused at first, because this isn't declared on UIImageView (like -setImageScaling: is on NSImageView). Rather, it's on UIView, since this the contentMode property is common to all views (and translates nearly directly to the underlying layer's property).

ace2600
Jul 2, 2008, 08:31 AM
Thanks kpua! That worked.

ribeto
Apr 25, 2011, 12:39 PM
Thanks setting the contentMode fixed it for me as well

I'm not sure, but I believe what you want is view.contentMode = UIViewContentModeScaleAspectFit.

I was confused at first, because this isn't declared on UIImageView (like -setImageScaling: is on NSImageView). Rather, it's on UIView, since this the contentMode property is common to all views (and translates nearly directly to the underlying layer's property).