사용자 정의 UIButton 하위 클래스를 작성하여 완전히 사용자 정의 된 버튼을 작성합니다. 은 전체 제어를 갖습니다. 그래도 UButton 뷰에 서브 뷰 을 추가하려고하면 문제가 발생합니다. 그것이이 데모입니다 거품 있는 UIButton 자체 ..사용자 정의 UIButton 클래스의 하위 뷰가 클릭을 트리거하지 않습니다.
에되지 않습니다 때문에 하위 뷰 블록 "터치"이벤트 : 내가 먼저 프레임, 내 CustomNavigationButton을 만들 수는 ... 그것은 마젠타입니다. 화면에 마젠타 색이 보입니다. 둘째, 해당 CustomNavigationButton (녹색) 하위 뷰 을 추가하면 초록색으로 볼 수 있으므로 입니다. 녹색 사각형 (하위 뷰)을 클릭하면 "UIControlEventTouchUpInside" 이 내 CustomNavigationButton에서 호출되지 않습니다. .. 내 AppDelete에서
:CustomNavigationButton* mapBtn = [[CustomNavigationButton alloc] initWithFrame:CGRectMake(0, 0, 100, 25)];
mapBtn.backgroundColor = [UIColor magentaColor];
[mapBtn addTarget:self action:@selector(goMapHandler:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:mapBtn];
그리고 여기에 내가 알아 낸
@implementation CustomNavigationButton
@synthesize bg;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// STORE INITIAL FRAME
self.initialFrame = frame;
bg = [[UIView alloc] initWithFrame:CGRectMake(0, 20, 40, 40)];
bg.backgroundColor = [UIColor greenColor];
[bg setUserInteractionEnabled:YES];
[self addSubview:bg];
}
return self;
}
@end
감사합니다. 그것은 나를 미치게했습니다! – Jano