How can I change the default color of the button on iPhone?
如何更改iPhone上按钮的默认颜色?
5 个解决方案
#1
33
A common technique is to use an image for the background. Actually you can use a stretchable image:
一种常见的技术是使用图像作为背景。实际上你可以使用一个可伸缩的图像:
- (void)viewDidLoad {
UIImage *blueImage = [UIImage imageNamed:@"blueButton.png"];
UIImage *blueButtonImage = [blueImage stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[myButton setBackgroundImage:blueButtonImage forState:UIControlStateHighlighted];
}
The original image:
原始图片:
The end result:
最终结果:
#2
6
I came across this post that explains how to do this without images and completely in code.
我发现这篇文章解释了如何在没有图像和完全代码的情况下完成此操作。
http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/
http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/
Hope that helps.
希望有所帮助。
#3
2
Assuming you mean UIButton
, you can only change the title color using setTitleColor:forState:
.
假设您的意思是UIButton,您只能使用setTitleColor:forState:更改标题颜色。
You can't change the background color or the shape. You have to create your own control for that.
您无法更改背景颜色或形状。你必须为此创建自己的控件。
#4
0
I started this thread on iphonedevsdk.com.
我在iphonedevsdk.com上开始了这个帖子。
Hopefully we'll get an answer there if not here.
希望如果不在这里我们会得到答案。
#5
0
A great way to customize UIButtons is by directly manipulating the Core Animation Layers. You can find a good tutorial on "Cocoa is My Girlfriend"
自定义UIButtons的一个好方法是直接操作核心动画层。你可以找到关于“可可是我的女朋友”的好教程
http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/
http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/
#1
33
A common technique is to use an image for the background. Actually you can use a stretchable image:
一种常见的技术是使用图像作为背景。实际上你可以使用一个可伸缩的图像:
- (void)viewDidLoad {
UIImage *blueImage = [UIImage imageNamed:@"blueButton.png"];
UIImage *blueButtonImage = [blueImage stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[myButton setBackgroundImage:blueButtonImage forState:UIControlStateHighlighted];
}
The original image:
原始图片:
The end result:
最终结果:
#2
6
I came across this post that explains how to do this without images and completely in code.
我发现这篇文章解释了如何在没有图像和完全代码的情况下完成此操作。
http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/
http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/
Hope that helps.
希望有所帮助。
#3
2
Assuming you mean UIButton
, you can only change the title color using setTitleColor:forState:
.
假设您的意思是UIButton,您只能使用setTitleColor:forState:更改标题颜色。
You can't change the background color or the shape. You have to create your own control for that.
您无法更改背景颜色或形状。你必须为此创建自己的控件。
#4
0
I started this thread on iphonedevsdk.com.
我在iphonedevsdk.com上开始了这个帖子。
Hopefully we'll get an answer there if not here.
希望如果不在这里我们会得到答案。
#5
0
A great way to customize UIButtons is by directly manipulating the Core Animation Layers. You can find a good tutorial on "Cocoa is My Girlfriend"
自定义UIButtons的一个好方法是直接操作核心动画层。你可以找到关于“可可是我的女朋友”的好教程
http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/
http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/