How to change the default color(blue) of a UISwitch?
7 Answers
I think what you are looking for is something like this
UISwitch *testSwitch; //just something I made up
[testSwitch setOnTintColor:[UIColor greenColor]];

- 8,696
- 27
- 77
- 123

- 1,256
- 1
- 10
- 11
In Xcode 5 and iOS 7 it's now in the attributes inspector:
Changing the On Tint will change the button's color when it's turned on.
I hope that's what you were looking for! Even though you posted that question like three years ago.

- 799
- 9
- 21
Swift 3 Swift 4
workable solution
var switcher = UISwitch()
switcher.onTintColor = .green
switcher.tintColor = .green

- 26,359
- 19
- 112
- 194
Prior to iOS 5, without writing your own custom UISwitch
control, perhaps using a UISegmentedControl
, Apple did not allow you to change the color of a standard UISwitch
.
There is a private property setAlternateColor: YES
which will change the color to orange, and you would need to create a category for the UISwitch
class, but this will not be approved in the Apple review process.
Here are a few custom UISwitch
projects for use in iOS 3.0 - 4.1:
- http://osiris.laya.com/projects/rcswitch/
- http://www.alexcurylo.com/blog/2010/07/30/custom-uiswitch/
- StackOverflow Anser: https://stackoverflow.com/a/5088099/171206 (using
UISegmentedControl
)
Introduced in iOS 5, the UISwitch
now has an onTintColor
property.
[mySwitch setOnTintColor: [UIColor blackColor]];
Set tint color for a specific UISwitch:
var switcher = UISwitch()
switcher.onTintColor = .red
switcher.tintColor = .red
Set tint color for your app:
let switchApperence = UISwitch.appearance()
switchApperence.tintColor = .red
switchApperence.onTintColor = .red

- 322
- 1
- 12
-
1Why do we need to set the tintColor attribute? It is working for me as expected with just onTintColor being set. – Sai Manoj Kumar Yadlapati Jun 19 '20 at 09:37
Finally, with iOS5 you can change the color of the switch with the property onTintColor.
UISwitch *s = [[UISwitch alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
s.on = YES;
s.onTintColor = [UIColor redColor];
[self.view addSubview:s];
[s release];
produce this
I hope this help !

- 6,235
- 8
- 54
- 93