2012-04-04 186 views
0

我希望能夠在用戶按下按鈕時更改任何按鈕的圖像,然後當它們釋放時,之前存在的圖像將被放回。UIImage按鈕(圓形按鈕)

所以基本上當他們按下按鈕時,他們的手指圖像會改變,當他們釋放時,IB中指定的原始圖像被放回。

我該怎麼做?這是我迄今爲止的代碼。

- (IBAction)btnOne:(id)sender { 
    result.text = [self appendresult:@"1"]; 

    //Changes the button image upon touch 
    [btnOne setImage:[UIImage imageNamed:@"NumberBtn1.png"] forState:UIControlStateNormal]; 
    [btnOne setImage:[UIImage imageNamed:@"NumberBtn1Alt.png"] forState:UIControlStateHighlighted]; 
    [btnOne setImage:[UIImage imageNamed:@"NumberBtn1Alt.png"] forState:UIControlStateSelected]; 
    btnOne.showsTouchWhenHighlighted = YES; 
} 
+0

我看到你是StackOverflow的新手,如果這個答案對你有幫助,那麼請標記爲正確。 – 2012-04-04 02:20:14

回答

1

把你的代碼...

[btnOne setImage:[UIImage imageNamed:@"NumberBtn1.png"] forState:UIControlStateNormal]; 
    [btnOne setImage:[UIImage imageNamed:@"NumberBtn1Alt.png"] forState:UIControlStateHighlighted]; 
    [btnOne setImage:[UIImage imageNamed:@"NumberBtn1Alt.png"] forState:UIControlStateSelected]; 
    btnOne.showsTouchWhenHighlighted = YES; 
viewDidLoad,而不是在 IBAction

,則只需確保您在Interface Builder按鈕被正確連接到IBOutlet你爲它創建。