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

Doug Smith picture Doug Smith · Oct 4, 2013 · Viewed 13.6k times · Source

It looks like this whenever off:

enter image description here

While I'd prefer more of a grey background. Do I really have to use a UIImageView?

Answer

Barry Wyckoff picture Barry Wyckoff · Nov 18, 2013

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

First you need to import QuartzCore.

#import <QuartzCore/QuartzCore.h>

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:)