14

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

shim
  • 9,289
  • 12
  • 69
  • 108
k06a
  • 17,755
  • 10
  • 70
  • 110
  • For anyone trying to get this look, I'll repeat the essence of my comment under the accepted answer: instead of white, set tint color to a light gray or an "off-white" (a custom color that is about 80% white). Then that border will show against white. – ToolmakerSteve Mar 23 '17 at 21:08

3 Answers3

22

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.

sangony
  • 11,636
  • 4
  • 39
  • 55
  • If you remove [[UIView appearance] setTintColor:[UIColor whiteColor]]; then it will work. I ran a test and without setting the UIView tintColor you will get the UISwitch border to any color you need. – sangony Feb 23 '14 at 02:26
  • Yes, it works, but I need set tint color to white. I wanna this step `self.mySwitch.tintColor = [UIColor grayColor];` to solve my problem, but it is not... – k06a Feb 23 '14 at 08:32
  • Is it feasible for you to use self.view.backgroundColor = [UIColor whiteColor]; instead of [[UIView appearance] setTintColor:[UIColor whiteColor]]; ? – sangony Feb 23 '14 at 14:29
  • 2
    As I said, I tested it and you cannot get the results you want using setTintColor. If using setting the background color really does not satisfy your goals, I suggest posting a new question specifically asking how to display a UISwitch border while have setTintColor set to white. Sorry I couldn't help you. – sangony Feb 23 '14 at 21:49
  • 2
    To clarify for anyone else reading this answer: tint color (currently) *only* controls the *border color shown when switch is off* - which is what is wanted here. To make this visible against white, set it to any color other than white. To match the look shown in the question, set it to a light gray or an "off-white" (a custom value that isn't 100% white, perhaps 80%). – ToolmakerSteve Mar 23 '17 at 21:04
4

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.

McDaddy
  • 144
  • 6
2

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.

shim
  • 9,289
  • 12
  • 69
  • 108
Daniel Bowden
  • 988
  • 1
  • 10
  • 23