Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ace2600

macrumors member
Original poster
Mar 16, 2008
71
0
Austin, Texas
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).
 
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).
 
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).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.