sudo
sudo

Reputation: 5804

Set the stroke color for a UISwitch when it's on?

I have a UISwitch that needs to have the same style when it's on as when it's off. The only difference would be where the little circle is.

It looks like this when it's off:

enter image description here

… which is good. But when I turn it on, the stroke disappears:

enter image description here

How do I make it keep the stroke when it's on? If that isn't possible, can I at least make it tinted when it's off and not just when it's on?

Upvotes: 1

Views: 1204

Answers (1)

klcjr89
klcjr89

Reputation: 5902

Apple may reject your app for not showing a different color for the On state, however I believe this is what you're wanting: This will show the 'stroke' for each state now.

@property (nonatomic, strong) IBOutlet UISwitch *theSwitch;

self.theSwitch.layer.borderColor = [UIColor colorWithRed:229.0/255.0 green:229.0/255.0 blue:229.0/255.0 alpha:1.0].CGColor;
self.theSwitch.layer.borderWidth = 1.5;
self.theSwitch.layer.cornerRadius = 31.0/2.0;

Results:

enter image description here enter image description here

Upvotes: 6

Related Questions