Search code examples
objective-cuiviewios6interface-builderautoresize

Autoresize Height and Width Proportionally Interface Builder


I have a UIImageView that is set to autoresize it's height based on the height of the Superview, i.e. when the In Call Status bar comes down. How do I make the entire view resize proportionally so that the width of the UIImageView changes when the height changes?

I would like to do this in Interface Builder, but programmatically can be used as well.

Thanks


Solution

  • The easiest way in iOS 6 is to use the (new in iOS 6) autolayout feature. It is very easy to make a view's width always be a fixed proportion of its height.

    Otherwise you'll have to detect the change in your view controller's layoutSubviews and use code to resize the UIImageView.

    However, consider the alternative of letting image resize rather than the whole image view. If you give the UIImageView the right contentMode, it will automatically resize the image proportionally if the view's height changes.