0
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 180, 180)];
myLabel.backgroundColor = [UIColor greenColor];
[self.view addSubview:myLabel];
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[self addTarget:self action:@selector(show) forControlEvents:UIControlEventTouchDown];
myButton.frame = CGRectMake(80.0, 120.0, 30, 30);
myButton.showsTouchWhenHighlighted = YES;
[self addSubview:myButton];
작동 버튼 작동 (show:
전화),하지만 버튼이 작동하지 않습니다 [myLabel addSubview:myButton];
을 사용할 수 없습니다. 이유가 확실하지 않은가요?있는 UIButton이 방법으로
---------------- 편집 & 솔루션은 ------------ 기본적으로 감사 @KennyTM
UILabel의 취급하지 않습니다 모든 사건. 라벨의 userInteractionEnabled
속성을 YES
으로 설정해야합니다.
또한 UILabel 상단에 UIButton을 추가하지 않는 것이 좋습니다.
그냥 UIView의 모든 하위 클래스라고 생각해 주셔서 감사합니다. –
@william : UILabel *은 UIView의 하위 클래스이며, 명시 적으로 'userInteractionEnabled'를 명시 적으로 해제합니다. – kennytm