Re: UIImageView Scaling

Rick Aurbach


I haven’t explored your argument in a test environment, but the reason I said the call to setNeedsLayout() was in ‘addition’ to the call to sizeToFit() is the following excerpt from the documentation of UIImageView (color enhancement is mine):

var image: UIImage?

The image displayed in the image view.


var image: UIImage? { get set }


This property contains the main image displayed by the image view. This image is displayed when the image view is in its natural state. When highlighted, the image view displays the image in its highlightedImage property instead. If that property is set to nil, the image view applies a default highlight to this image. If the animationImages property contains a valid set of images, those images are used instead.

Changing the image in this property does not automatically change the size of the image view. After setting the image, call the sizeToFit() method to recompute the image view’s size based on the new image and the active constraints. 

This property is set to the image you specified at initialization time. If you did not use the init(image:) or init(image:highlightedImage:) method to initialize your image view, the initial value of this property is nil.

So, at an absolute minimum, this is a documentation issue…



Join { to automatically receive all group messages.