2011-09-16 104 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的

相關問題