1

UIButton设置为以下代码:

UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 27, 27)];
[btn setBackgroundImage:[UIImage imageNamed:@"imgUp.png"] forState:UIControlStateNormal];
[btn setBackgroundImage:[UIImage imageNamed:@"imgDown.png"] forState:UIControlStateHighlighted];
[btn addTarget:self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside];

btw如果我快速触摸,imgDown.png则不会出现,但btnPressed:会触发动作。怎么可能修好?任何帮助表示赞赏:)

4

4 回答 4

1

在您的代码中添加这一行:

[btn setBackgroundImage:[UIImage imageNamed:@"imgDown.png"] forState:UIControlStateSelected];
于 2012-09-27T08:47:11.110 回答
0

您应该为 btnPressed: 函数内的按钮 (btn) 调用 setHiglighted: 方法。

于 2012-09-27T08:43:15.020 回答
0

它工作正常我会测试它请检查你的图像并尝试它:

UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 27, 27)];
[button setBackgroundImage:[UIImage imageNamed:@"rainy.jpg"] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"Icon.png"] forState:UIControlStateHighlighted];
[button addTarget:self action:@selector(btnPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view button];
于 2012-09-27T11:05:38.590 回答
0

下面的代码可以解决问题。

-(void)btnPressedDelay{

    //original code in btnPressed: method
}

- (void) btnPressed:(id)sender
{    

    [self performSelector:@selector(btnPressedDelay) withObject:nil afterDelay:0];
// 0 did the magic here

}
于 2012-09-27T09:19:51.613 回答