addSubView to UIButton

做~自己de王妃 提交于 2019-11-30 00:20:26

I found a quick solutions. I needed to set the asyncimageview to the following:

asyncImage.userInteractionEnabled = NO;
        asyncImage.exclusiveTouch = NO;

After this it worked!

user842059

try:

[UIButton buttonWithType:UIButtonTypeCustom];

instead of:

[UIButton buttonWithType:UIButtonControlType];

Have you tried to put:

[asyncImage setUserInteractionEnabled:YES];

in the same sitiation i make this action: inherit from UIButton and add all labels and imageview's of button to self, finally put new button to view as last subview and add targets of self button to this last button(also set backgroundColor to clearColor for transparent). now it will be clickable and works fine.

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.

In Swift, test that is you have your UIButton blocked

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