2

I should customize a UISwitch with YES and NO instead of ON and OFF, what can I do? I don't know the code for make it.

cyclingIsBetter
  • 17,447
  • 50
  • 156
  • 241
  • There is no public API to do this sort of modification to `UISwitch`. If you would like there to be, please [file an enhancement request](http://bugreport.apple.com). – Dave DeLong Mar 29 '11 at 18:05
  • Try this - http://www.catamount.com/blog/?p=1063 Also, possible duplicate of this: So, take a look: http://stackoverflow.com/questions/981061/change-label-of-uiswitch – Tejaswi Yerukalapudi Mar 29 '11 at 17:42
  • I made a custom UISwitch. Check it out here, it's free for any usage: http://xcodenoobies.blogspot.com/2013/04/free-custom-uiswitch-flexible-colors.html – GeneCode Apr 08 '13 at 03:58

1 Answers1

3

The documentation doesn't show properties for changing the style of a UISwitch, the way I've always implemented such a feature was using a UISlider, and you can set the properties only via code (the advanced properties at least). For "yes" and "no" you can make images to set to the left and right side of the slider, and for the transition effect you can use a normal animation function

[UIView animationWithDuration:0.1f animation^(void){
   //code here
}completion(BOOL finished){
   // set the picture here so that you don't see a squished imaged get enlarged
}];

I don't know the properties off the top of my head so you will have to play around with it, it's probably UISlider.layer.property so once you type the second . then a list should come up which you can scroll through to find what matches what you are looking for, but don't quote me, I'm not exactly sure on that.

Sam Spencer
  • 8,492
  • 12
  • 76
  • 133
Isaac Paul
  • 1,959
  • 2
  • 15
  • 20