How can I change the default color of the button on iPhone?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With