Setting content mode for something besides UIImageView in iOS
Asked Answered
H

1

2

This answer shows the various effects of setting the content mode of a UIImageView.

Since UIView also has a content mode setting in the Interface Builder, I want to know why setting it doesn't affect any subviews that are in it.

Here is an example that I tried. The blue view is a UIView and the yellow view is a UILabel.

enter image description here

But if I set the mode to Top for the UIView, the label just stays in the same place.

enter image description here

Does content mode only work for UIImageViews? If it doesn't work for UIViews, why is it even there?

Homotaxis answered 22/8, 2015 at 3:56 Comment(2)
Already have question and answer here : [#12828210 [1]: #12828210Compensable
@anhtu, thanks, I missed that one.Homotaxis
M
3

The contentMode modifies only the views' contents and not its subviews'. So if you have a custom view and you draw something in its drawRect then you will see that it gets changed every time you change the contentMode of your view.

Now in case of UIImageView, the image is actually the content of the view (which is internally drawn in its drawRect), so you can see the image changing when you change the contentMode of your UIImageView.

Milliard answered 22/8, 2015 at 4:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.