[英]Add a subview to a UIImageView that is the view outlet of a UIViewController in IB
I have a UIViewController object in a .xib file. 我在.xib文件中有一个UIViewController对象。 I add a UIImageView to it, and then try to add a button as a subview of the UIImageView. 我添加了一个UIImageView,然后尝试添加一个按钮作为UIImageView的子视图。 It instead replaces the UIImageView. 它取而代之的是UIImageView。 It works fine if both are subviews of a UIView. 如果两者都是UIView的子视图,它工作正常。 What gives? 是什么赋予了? I thought this would work since UIImageView is a subclass of UIView? 我认为这可行,因为UIImageView是UIView的子类?
Only Apple knows. 只有Apple知道。
However, look at here for a workaround: 但是,请查看此处的解决方法:
Apple Interface Builder: adding subview to UIImageView Apple Interface Builder:将子视图添加到UIImageView
A UIImageView
is it's own object and a UIButton
is its own object. UIImageView
是它自己的对象, UIButton
是它自己的对象。 A UIImageView
is an outlet placeholder for an image. UIImageView
是图像的插座占位符。 If you're trying to add a background image to a button you can use the background image property or if you'd like the background to span beyond the bounds of the button you can drop a UIView
onto IB and style that using code or subclassing UIImageView
. 如果您尝试将背景图像添加到按钮,则可以使用背景图像属性,或者如果您希望背景超出按钮的范围,则可以将UIView
拖放到IB上并使用代码或子类化来设置样式UIImageView
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.