2012-12-04 170 views
2

我改變了按鈕的顏色使用下面的代碼:IOS:改變按鈕的顏色

[self.testButton setBackgroundColor:[UIColor redColor]]; 

,但我有一個奇怪的按鈕:

enter image description here

爲什麼按鈕的背景顏色也沒變化?

+1

按鈕背景的確發生了變化,它只是按鈕本身是有不同的看法。 – CodaFi

+0

將testButton樣式設置爲'UIButtonTypeCustom'並檢查。它應該顯示紅色。 – iDev

回答

10

可以導入#import <QuartzCore/QuartzCore.h>和嘗試這個,

self.testButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
self.testButton.backgroundColor = [UIColor redColor]; 
self.testButton.layer.borderColor = [UIColor blackColor].CGColor; 
self.testButton.layer.borderWidth = 0.5f; 
self.testButton.layer.cornerRadius = 10.0f; 

否則你可以使用一些自定義的圖片作爲此按鈕的背景圖像。

2

改變你的.xib按鈕類型的自定義屬性中檢查再檢查你的代碼

[self.testButton setBackgroundColor:[UIColor redColor]];