繁体   English   中英

以编程方式添加UIButton时无法单击

[英]UIButton not clickable when adding it programmatically

我正在创建包含两个UILabelUIButton自定义UIView ,所以我创建了一个子类来实现这一点。

现在,过程看起来像:

- (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;
}

按钮出现在UIView上,但不可单击。 我试图设置self.userInteractionEnabled = YES; 和一些事情,但仍然没有结果:(

这是我有史以来最愚蠢的错误。 透明的UINavigationBar阻止了触摸。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM