Resizing images in UIImageView

Discussion in 'iOS Programming' started by ace2600, Jul 1, 2008.

  1. macrumors member

    Joined:
    Mar 16, 2008
    Location:
    Austin, Texas
    #1
    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).
     
  2. macrumors 6502

    Joined:
    Jul 25, 2006
    #2
    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).
     
  3. thread starter macrumors member

    Joined:
    Mar 16, 2008
    Location:
    Austin, Texas
  4. macrumors newbie

    Joined:
    Apr 18, 2010
    #4
    Thanks setting the contentMode fixed it for me as well

     

Share This Page