[英]UIButton not clickable when adding it programmatically
我正在創建包含兩個UILabel
和UIButton
自定義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.