我想更改按钮单击事件上的按钮图像。这是我正在尝试的。
-(IBAction)editObjectImage:(id)sender
{
if (editButtonState == NO)
{
[editButton setImage:nil forState:UIControlStateNormal];
[editButton setImage:[UIImage imageNamed:@"done2.png"] forState:UIControlStateNormal];
}
else
{
[editButton setImage:nil forState:UIControlStateNormal];
[editButton setImage:[UIImage imageNamed:@"edit.png"] forState:UIControlStateNormal];
}
}
但是我的Button图像没有改变。代码有什么问题?
最佳答案
我认为您不会绕过更改editButtonState
。您的代码可以简化为。
-(IBAction)editObjectImage:(id)sender
{
UIButton *theButton = (UIButton*)sender;
if (editButtonState == NO) {
[theButton setImage:[UIImage imageNamed:@"done2.png"] forState:UIControlStateNormal];
} else {
[theButton setImage:[UIImage imageNamed:@"edit.png"] forState:UIControlStateNormal];
}
editButtonState = !editButtonState;
}
关于iphone - 如何更改按钮上设置的图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6211878/