How can I change the default color of the button on iPhone?
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"
http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/
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:
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/
Hope that helps.
Assuming you mean UIButton
, you can only change the title color using setTitleColor:forState:
.
You can't change the background color or the shape. You have to create your own control for that.
I started this thread on iphonedevsdk.com.
Hopefully we'll get an answer there if not here.