Is possible to add images to an UISwitch background,like when the state is ON (be one background) and when the state is OFF (another background image)?
-
http://stackoverflow.com/questions/12400239/uiswitch-with-custom-image Hopefully that helps :) – StackBuddy Jan 24 '13 at 21:44
3 Answers
To change the background color (not image) all you have to do is below. This changes the off color for all UISwitch controls in realm.
[[UISwitch appearance] setTintColor:[UIColor brownColor]];//Off Color
_locationSwitch.onTintColor = [UIColor orangeColor];//On Color
If you want to use image, use the following cool hack of using the segmented control. https://stackoverflow.com/a/5088099/1705353
If you want to write a lot of code, you can write your own control. Valeriy Van pointed to: https://github.com/homick/iPhone-Snippets/tree/master/General
Also another resource is: http://www.raywenderlich.com/23424/photoshop-for-developers-creating-a-custom-uiswitch with code at: http://cdn2.raywenderlich.com/wp-content/uploads/2012/10/CustomSwitchResources.zip

- 1
- 1

- 713
- 1
- 8
- 16
You can recreate a custom UISwitch
by subclassing UIControl
. By doing this you can have full control over what the switch looks like. You can look take a look at SevenSwitch
. A custom UISwitch
replacement I've created. The on/off colors can be customized to your liking.

- 1,405
- 14
- 17
-
Please disclose any [affiliations](https://stackoverflow.com/help/promotion) and do not use the site as a way to promote your site through posting. See [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer). – Feb 26 '19 at 05:47
I would like to suggest you to follow Custom UISwitch & App Store approval to have a better idea, which is suggesting you to create a custom switch control.

- 1
- 1

- 5,173
- 2
- 26
- 54