Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the default color of the button on iPhone?

How can I change the default color of the button on iPhone?

like image 604
ebaccount Avatar asked Jun 04 '09 01:06

ebaccount


2 Answers

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:

alt text

The end result:

alt text

like image 146
Alexandre L Telles Avatar answered Oct 03 '22 06:10

Alexandre L Telles


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.

like image 38
AidenMontgomery Avatar answered Oct 03 '22 05:10

AidenMontgomery