1

Question - How do I scale the image in a UIImageView when in "centre" mode? (change frame doesn't work) I should clarify in that I would like to be able to do this programmatically.

I can scale the UIImageView by changing it's frame to something smaller but on and same center, and this works (I put a border on view to check), however the actual image in the UIImageView doesn't change. Remember the UIImageView mode has got to be "Centered".

Background: the reason I ask is because I have some images I want to scale between orientation changes, and they need to be centered, however their views can NOT have a "aspect fit" mode as some of the views are being rotated over time using a transformation, and having them auto-scale as orientation changes occur as they rotate won't work well.

Greg
  • 34,042
  • 79
  • 253
  • 454

1 Answers1

11

Try to set the contentScaleFactor (available in iOS 4.0) or the transform property:

imageView.contentScaleFactor = scale;

imageView.transform = CGAffineTransformMakeScale(scale,scale);
Felix
  • 35,354
  • 13
  • 96
  • 143
  • thanks phix23 - by the way I posted another related question http://stackoverflow.com/questions/6726423/how-can-i-get-the-scale-factor-of-a-uiimageview-whos-mode-is-aspectfit. Not sure if you know the answer. – Greg Jul 17 '11 at 20:03
  • thanks phix23 - by the way I posted another related question http://stackoverflow.com/questions/6726423/how-can-i-get-the-scale-factor-of-a-uiimageview-whos-mode-is-aspectfit. Not sure if you know the answer. – Greg Jul 17 '11 at 20:03