How do I make a UISwitch under iOS 7 not take the background colour of the view behind it?

后端 未结 6 438
终归单人心
终归单人心 2021-02-02 11:27

It looks like this whenever off:

\"enter

While I\'d prefer more of a grey backgrou

6条回答
  •  萌比男神i
    2021-02-02 12:03

    Here is how I changed the fill color of my iOS7 UISwitch.

    First you need to import QuartzCore.

    #import 
    

    Then set the background color and round the UISwitch's corners.

    UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(0.0, 0.0, 51.0, 31.0)];
    mySwitch.backgroundColor = [UIColor redColor];
    mySwitch.layer.cornerRadius = 16.0; // you must import QuartzCore to do this.
    [self addSubview:mySwitch];
    

    This will give you a UISwitch with a custom off (background) color.

    Hope this helps someone:)

提交回复
热议问题