2011-09-16 106 views

回答

3

只有一行代码。

[yourButton setBackgroundImage:[UIImage imageNamed:@"select-button.png"] forState:UIControlStateHighlighted]; 
+0

但我的按钮没有名称,因为它直接添加到Interface Builder中,我应该在'yourButton'中放置什么? thanx – Malloc

+0

我尝试给它一个IBOutlet的名字,并且我使用你的代码行,不幸的是,按钮图像没有被改变。 – Malloc

1

这最好是以编程方式完成,而不是在Interface Builder中完成。为您的按钮设置一个动作,使其在点击时按钮图像发生变化:

- (IBAction)buttonTapped:(id)sender 
{ 
    UIButton *theButton = (UIButton *)sender; 
    if ([theButton currentImage] == self.imageOne) { 
     [theButton setImage:self.imageTwo forState:UIControlStateNormal]; 
    } 
    else { 
     [theButton setImage:self.imageOne forState:UIControlStateNormal]; 
    } 

    // (remaining action code)... 
} 
+0

您更快然后我=)好! – Nekto

0

我认为最好的办法是使用两个相同的帧按钮,当用户单击Button1,Button1的隐藏和显示button2.if用户点击按钮2,隐藏BUTTON2并显示Button1的

相关问题