2013-10-16 58 views
1

我有一個UIButton,它具有預設的文本字體和顏色,我需要在點擊tap按鈕時立即更改。UIbutton在水龍頭後改變顏色

我嘗試:

- (IBAction)tapAction : (id)sender 
{ 
    // determine button from tag .. 
    [crtBtn setTitleColor:self.selectedTextColor forState:UIControlStateSelected]; 
    [crtBtn setTitleColor:self.selectedTextColor forState:UIControlStateNormal]; 
    [crtBtn setTitleColor:self.selectedTextColor forState:UIControlStateApplication]; 
    [crtBtn setTitleColor:self.selectedTextColor forState:UIControlStateHighlighted];  
    [crtBtn setNeedsDisplay]; 
} 

任何想法如何解決這一問題?

+0

你說的是標題的顏色或按鈕背景色? –

回答

2

試試這個代碼:

- (IBAction)tapAction : (id)sender 
    { 
    [sender setTitleColor:self.selectedTextColor forState:UIControlStateNormal] 
    } 
1

我想,你不爲你按鈕(帶crtBtn)設置IBOutlet中。

- (IBAction)tapAction : (id)sender 
{ 
    [crtBtn setTitleColor:self.selectedTextColor forState:UIControlStateNormal]; 
// or 
    [sender setTitleColor:self.selectedTextColor forState:UIControlStateNormal] 
} 
1

這個工作對我來說:

-(IBAction)tapAction: (UIButton *)sender 

{ 

[crtBtn setTitleColor:self.selectedTextColor forState:UIControlStateNormal]; 

}