[英]UIButton not clickable when adding it programmatically
I'm creating custom UIView
that contains two UILabel
s and UIButton
so I created a subclass to make this possible. 我正在创建包含两个
UILabel
和UIButton
自定义UIView
,所以我创建了一个子类来实现这一点。
Now the process looks like: 现在,过程看起来像:
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
self.backgroundColor = [UIColor whiteColor];
self.settingsButton = [[UIButton alloc] initWithFrame:CGRectMake(frame.size.width - 2 * margin, frame.size.height - titleHeight - dateHeight, buttonSize, buttonSize)];
[self.settingsButton setImage:[UIImage imageNamed:@"settings_icon"] forState:UIControlStateNormal];
[self addSubview:self.settingsButton];
[self.settingsButton addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
return self;
}
Button appears on UIView but it is not clickable. 按钮出现在UIView上,但不可单击。 I tried to set
self.userInteractionEnabled = YES;
我试图设置
self.userInteractionEnabled = YES;
and a couple things but still no result :( 和一些事情,但仍然没有结果:(
This is the most dumb mistake I've ever made. 这是我有史以来最愚蠢的错误。 Transparent
UINavigationBar
was blocking the touch. 透明的
UINavigationBar
阻止了触摸。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.