2012-12-04 58 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]];