addSubView to UIButton

前端 未结 6 1557
谎友^
谎友^ 2020-12-24 10:45

I\'m trying to add subviews to a UIButton. This is working fine right now. But the button isn\'t clickable anymore as soon as I add the subviews.

I use the following

6条回答
  •  旧时难觅i
    2020-12-24 11:31

    The important thing here is to make sure that userInteractionEnabled will be set to NO. Fortunately it works immediately for UIImageView and UILabel (maybe for other subclasses of a UIView but those are the most popular subviews added to button) because by default for this classes it is set to NO by default. Unfortunately it is set to YES in UIView so make sure to change it in that case. Messing around with any other flags shouldn't be necessary. The nature of problem is that many people do not know that default value of this flag is different in subclasses.

提交回复
热议问题