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

后端 未结 5 1786
终归单人心
终归单人心 2020-12-23 23:13

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

相关标签:
5条回答
  • 2020-12-23 23:59

    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/

    0 讨论(0)
  • 2020-12-24 00:05

    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

    0 讨论(0)
  • 2020-12-24 00:05

    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.

    0 讨论(0)
  • 2020-12-24 00:09

    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.

    0 讨论(0)
  • 2020-12-24 00:10

    I started this thread on iphonedevsdk.com.

    Hopefully we'll get an answer there if not here.

    0 讨论(0)
提交回复
热议问题