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

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

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

5条回答
  •  挽巷
    挽巷 (楼主)
    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

提交回复
热议问题