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

时间:2017-11-21 17:28:33

标签: ios objective-c iphone uiview uibutton

我正在创建包含两个UIViewUILabel的自定义UIButton,因此我创建了一个子类来实现此目的。

现在流程如下:

- (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;和一些事情,但仍然没有结果:(

1 个答案:

答案 0 :(得分:2)

这是我犯过的最愚蠢的错误。透明UINavigationBar阻止了触摸。