在iOS中为UIImageView以外的内容设置内容模式 [英] Setting content mode for something besides UIImageView in iOS
问题描述
此答案显示了设置
内容模式仅适用于 现在,对于 This answer shows the various effects of setting the content mode of a Since Here is an example that I tried. The blue view is a But if I set the mode to Top for the Does content mode only work for The Now in case of 这篇关于在iOS中为UIImageView以外的内容设置内容模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!UIImageViews
吗?如果UIViews
不能使用,为什么还可以呢?contentMode
仅修改视图的内容,而不修改其子视图.因此,如果您有一个自定义视图,并且在其drawRect
中绘制了一些内容,那么您每次更改视图的contentMode
时都会看到它被更改.UIImageView
,图像实际上是视图的内容(在其drawRect
中内部绘制),因此,当您更改UIImageView的contentMode
时,可以看到图像发生了变化. UIImageView
.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.UIView
and the yellow view is a UILabel
.UIView
, the label just stays in the same place.UIImageViews
? If it doesn't work for UIViews
, why is it even there?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.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.