Setting content mode for something besides UIImageView in iOS

寵の児 提交于 2019-12-11 03:36:02

问题


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.

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

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


回答1:


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.



来源:https://stackoverflow.com/questions/32152138/setting-content-mode-for-something-besides-uiimageview-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!