简体   繁体   English

将子视图添加到UIImageView,它是IB中UIViewController的视图出口

[英]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.

相关问题 不使用IB将UIImageView添加为UIViewController的子视图 - Add a UIImageView as a subview of a UIViewController without using IB 如何在不使用IB的情况下将TableView Controller作为子视图添加到UIViewController? - How to add a TableView Controller as a subView to a UIViewController without using IB? 如何将 UIViewController 的视图添加为子视图 - How to add an UIViewController's view as subview 为什么“查看” UIViewController上的插座? - Why is “view” an outlet on UIViewController? 如何将子视图添加到UIViewController? - How to add a subview to a UIViewController? 如何在 UIViewController 中将 uitabbarcontroller 添加为子视图 - How to add uitabbarcontroller as a subview in UIViewController UIViewController:将self.view设置为我的视图或将我的视图添加为子视图? - UIViewController: set self.view to my view or add my view as subview? 如何为包含UITabBarController的UIViewController设置视图出口? - How to set view outlet for a UIViewController that contains a UITabBarController? 查看所有内容:UIWindow子视图VS UIViewController子视图 - View on top of everything: UIWindow subview VS UIViewController subview 通过界面生成器将子视图添加到 UIImageView - add subview to UIImageView via interface builder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM