如何更改 iPhone 上按钮的默认颜色?
问问题
27844 次
5 回答
33
一种常见的技术是使用图像作为背景。实际上,您可以使用可拉伸的图像:
- (void)viewDidLoad {
UIImage *blueImage = [UIImage imageNamed:@"blueButton.png"];
UIImage *blueButtonImage = [blueImage stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[myButton setBackgroundImage:blueButtonImage forState:UIControlStateHighlighted];
}
原图:
最终结果:
于 2009-06-04T01:42:25.333 回答
6
我遇到了这篇文章,它解释了如何在没有图像的情况下完全使用代码来做到这一点。
http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/
希望有帮助。
于 2010-10-21T13:50:57.660 回答
2
假设您的意思是UIButton
,您只能使用更改标题颜色setTitleColor:forState:
。
您不能更改背景颜色或形状。您必须为此创建自己的控件。
于 2009-06-04T01:13:02.990 回答
0
我在 iphonedevsdk.com 上 启动了这个线程。
如果不是在这里,希望我们能在那里得到答案。
于 2009-07-06T21:11:56.117 回答
0
自定义 UIButton 的一个好方法是直接操作核心动画层。你可以找到一个很好的教程“可可是我的女朋友”
http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/
于 2010-11-30T23:40:28.410 回答