k06a
k06a

Reputation: 18805

How to set UISwitch border color?

My app has:

[[UIView appearance] setTintColor:[UIColor whiteColor]];

And here is what I have when on:

switch in on position

and off:

switch in off position

I need to make UISwitch border visible like in Settings.app:

Settings app

Upvotes: 14

Views: 11544

Answers (3)

Daniel Bowden
Daniel Bowden

Reputation: 988

Rather than using the appearance proxies you can also use:

[self.mySwitch setThumbTintColor:[UIColor blueColor]];
[self.mySwitch setOnTintColor:[UIColor redColor]];

ie. Use setOnTintColor for the background/border color.

Upvotes: 2

McDaddy
McDaddy

Reputation: 144

Will you please try adding this line to your AppDelegate's didFinishLaunchingWithOptions

[[UISwitch appearance] setTintColor:[UIColor grayColor]];

This should apply the chosen Tint color on all your UISwitch controls.

Upvotes: 4

sangony
sangony

Reputation: 11696

Your [[UIView appearance] setTintColor:[UIColor whiteColor]]; is interfering with the tint color of your switch. The command to set the tint color is self.mySwitch.tintColor = [UIColor grayColor]; which sets the color used to tint the outline of the switch when it is turned off.

Upvotes: 22

Related Questions