How to change the UISwitch default color(blue)

48,142

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:

enter image description here

Changing the On Tint will change the button's color when it's turned on.

enter image description here

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:

  1. http://osiris.laya.com/projects/rcswitch/
  2. http://www.alexcurylo.com/blog/2010/07/30/custom-uiswitch/
  3. 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
Share:
48,142
Prasad
Author by

Prasad

I am new to iPhone Development

Updated on July 22, 2022

Comments

  • Prasad
    Prasad almost 2 years

    How to change the default color(blue) of a UISwitch?

  • Sai Manoj Kumar Yadlapati
    Sai Manoj Kumar Yadlapati almost 4 years
    Why do we need to set the tintColor attribute? It is working for me as expected with just onTintColor being set.