Change color of UISwitch in "off" state Change color of UISwitch in "off" state ios ios

Change color of UISwitch in "off" state


My solution with #swift2:

let onColor  = _your_on_state_colorlet offColor = _your_off_state_colorlet mSwitch = UISwitch(frame: CGRect.zero)mSwitch.on = true/*For on state*/mSwitch.onTintColor = onColor/*For off state*/mSwitch.tintColor = offColormSwitch.layer.cornerRadius = mSwitch.frame.height / 2.0mSwitch.backgroundColor = offColormSwitch.clipsToBounds = true

Result:

enter image description here


Try using this

yourSwitch.backgroundColor = [UIColor whiteColor];youSwitch.layer.cornerRadius = 16.0;

All thanks to @Barry Wyckoff.


You can use the tintColor property on the switch.

switch.tintColor = [UIColor redColor]; // the "off" colorswitch.onTintColor = [UIColor greenColor]; // the "on" color

Note this requires iOS 5+