点击事件更改按钮图像

时间:2014-03-25 09:45:11

标签: ios7 xcode5

我想更改按钮图像。当我点击按钮时它将改变它的图像,点击后按钮将以正常形式返回。我想知道如何实现这个?请帮帮我。

3 个答案:

答案 0 :(得分:1)

    UIImage *buttonImage = [UIImage imageNamed:@"image.png"];
    [sender setImage:buttonImage forState:UIControlStateHighlighted];
    UIImage *buttonImage1 = [UIImage imageNamed:@"image.png"];
    [sender setImage:buttonImage1 forState:UIControlStateNormal];

答案 1 :(得分:0)

您可以自定义"突出显示的"您在Interface Builder中的状态,或使用此代码:

[self.button setImage:[UIImage imageNamed:@"normal"] forState:UIControlStateNormal];
[self.button setImage:[UIImage imageNamed:@"pressed"] forState:UIControlStateHighlighted];

答案 2 :(得分:0)

首先修复Backgroudimage is @"image1.jpeg"中的xib,然后

- (IBAction)mybutton:(id)sender
{
 [_buttonrefrence setBackgroundImage:[UIImage imageNamed:@"download.jpeg"] forState:UIControlStateHighlighted];
}