如何更改iPhone上按钮的默认颜色?
答
一种常见的技术是将图像用于背景。其实你可以使用可伸缩的图像:
- (void)viewDidLoad {
UIImage *blueImage = [UIImage imageNamed:@"blueButton.png"];
UIImage *blueButtonImage = [blueImage stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[myButton setBackgroundImage:blueButtonImage forState:UIControlStateHighlighted];
}
原始图像:
最终结果是:
答
假设您的意思是UIButton
,您只能使用setTitleColor:forState:
更改标题颜色。
您无法更改背景颜色或形状。你必须为此创建自己的控制。
答
我遇到这篇文章,解释了如何做到这一点,没有图像,完全在代码中。
http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/
希望有所帮助。
答
定制UIButtons的好方法是直接操作Core Animation Layers。你可以找到一个很好的教程上的“可可是我的女朋友”
http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/
谢谢,它的工作。 – ebaccount 2009-06-04 19:16:20