我有UIButton
两种状态。button
我在forUIControlEventTouchDown
事件中添加了一个动作。当button
处于正常状态时一切正常,当我触摸button
. 但是当我触摸时没有任何button
反应,只有当我松开手指时,状态才会变为正常(Like )。selected state
button
UIControlEventTouchUpInside
我该如何解决这个问题?
我使用这种方法创建我的按钮:
- (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];
}