1
두 가지 상태의 간단한 UIButton
이 있습니다. UIControlEventTouchDown
이벤트의 경우 button
에 작업을 추가했습니다. button
이 정상 상태 일 때 모두 효과적입니다. button
을 터치하면 메소드가 호출됩니다. 그러나 button
이 selected state
에있을 때 button
을 터치해도 아무 것도 나타나지 않습니다. 손가락을 떼면 상태가 정상 (예 : UIControlEventTouchUpInside
)으로 바뀝니다.선택한 버튼의 UIControlEventTouchDown이 올바로 작동하지 않습니다.
어떻게 해결할 수 있습니까?
나는이 방법을 사용하여 내 버튼을 만듭니다
- (UIButton *) createButtonWithFrame:(CGRect)frame title:(NSString *)title {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:frame];
[button setTitle:title forState:UIControlStateNormal];
[button setTitleColor:UIColorFromRGB(0x3a3a3a) forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
[[button titleLabel] setFont:[UIFont fontWithName:@"Gotham-Bold" size:10]];
[button setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"button_pressed.png"] forState:(UIControlStateSelected)];
[button setAdjustsImageWhenHighlighted:NO];
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown];
return button;
}
그리고 buttonPressed:
이 같다 :
- (void) buttonPressed:(UIButton *)sender {
[sender setSelected:!sender.selected];
}
추가하면 btn = (UIbutton *) 보낸 사람; –
죄송합니다. 내 실수 ... 편집 된 답변을 확인하십시오. – Venkat