How to change the UISwitch default color(blue)
Solution 1
I think what you are looking for is something like this
UISwitch *testSwitch; //just something I made up
[testSwitch setOnTintColor:[UIColor greenColor]];
Solution 2
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.
Solution 3
Swift 3 Swift 4
workable solution
var switcher = UISwitch()
switcher.onTintColor = .green
switcher.tintColor = .green
Solution 4
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]];
Solution 5
Swift 3:
yourSwitch.onTintColor = .red
Comments
-
Prasad almost 2 years
How to change the default color(blue) of a UISwitch?
-
Sai Manoj Kumar Yadlapati almost 4 yearsWhy do we need to set the tintColor attribute? It is working for me as expected with just onTintColor being set.