2013-05-16 44 views
0

我需要一種快速方法來更改實時UIButton的顏色(以響應委託調用)。所以按鈕是用白色背景(標準)繪製的,然後當代表呼叫來到時,它需要變成藍色/紅色背景。外部事件後UIButton顏色變化

我想:

btn.backgroundColor = [UIColor redColor]; 
     [btn setNeedsDisplay]; 

這不工作...

而且這將是一個很好的IDEEA更改按鈕文本的顏色...如何這樣做?

回答

2

嘗試使用這樣的:

[button setBackgroundColor:someColor forState:UIControlStateNormal]; 

它是否適合你..?我假設您已將您的按鈕設爲自定義按鈕類型。 如果它的工作,你可能要考慮,接受了答案

0

首先請您UIButton類型的自定義..

UIButton* myButton = [UIButton buttonWithType:UIButtonTypeCustom]; 

[myButton setbackgroundColor:[UIColor blueColor] forState: UIControlStateNormal]; 
[myButton setTitleColor:[UIColor blueColor] forState: UIControlStateNormal];