如何在Interface Builder中将子视图添加到UIButton [英] How can I addSubview to UIButton in Interface Builder
问题描述
就像我说的,我在Interface Builder中添加了一个UIButton,我想添加一个UILabel,UIImageView作为按钮的子视图,但是我不能在IB中添加任何对象。有谁知道怎么做?非常感谢。
Like I said, I add a UIButton in Interface Builder, I want add a UILabel、UIImageView as the button's subviews, but I can't add any object on it in IB. IS anybody know how to do this? Thank you very much.
我可以使用代码实现这一点,但我希望在IB中实现它,所以我可以在任何我想要的类中使用它。
I can use code to achieve that, but I want achieve it in IB, so I can use it in any class I want.
推荐答案
我之前通过添加UIView(而不是UIButton)来完成此操作,然后将UIButton和UILabel添加到UIView。来自UIButton的点击仍然有效,你也有一个标签。你也可以添加其他任何东西。
I have done this before by adding a UIView (instead of the UIButton) then add the UIButton and UILabel to the UIView. The tap from the UIButton still works and you have a label too. You can also add anything else like this.
这篇关于如何在Interface Builder中将子视图添加到UIButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!