Swift 4 is the easiest and fastest way to get it in 3 steps:
// background color is the color of the background of the switch switchControl.backgroundColor = UIColor.white.withAlphaComponent(0.9) // tint color is the color of the border when the switch is off, use // clear if you want it the same as the background, or different otherwise switchControl.tintColor = UIColor.clear // and make sure that the background color will stay in border of the switch switchControl.layer.cornerRadius = switchControl.bounds.height / 2
If you manually resize the switch (for example, using autolayout), you will also have to update switch.layer.cornerRadius , for example, by overriding layoutSubviews and after calling the super-update of the corner radius:
override func layoutSubviews() { super.layoutSubviews() switchControl.layer.cornerRadius = switchControl.bounds.height / 2 }
Milan NosΓ‘ΔΎ Feb 23 '18 at 12:30 2018-02-23 12:30
source share