Add a subview to a UIImageView that is the view outlet of a UIViewController in IB

女生的网名这么多〃 提交于 2019-12-14 01:19:52

问题


I have a UIViewController object in a .xib file. I add a UIImageView to it, and then try to add a button as a subview of the UIImageView. It instead replaces the UIImageView. It works fine if both are subviews of a UIView. What gives? I thought this would work since UIImageView is a subclass of UIView?


回答1:


Only Apple knows.

However, look at here for a workaround:

Apple Interface Builder: adding subview to UIImageView




回答2:


A UIImageView is it's own object and a UIButton is its own object. A UIImageView is an outlet placeholder for an image. 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.



来源:https://stackoverflow.com/questions/4892770/add-a-subview-to-a-uiimageview-that-is-the-view-outlet-of-a-uiviewcontroller-in

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