Archive for July 30th, 2010

Custom UISwitch

So it’s getting along to Pretty Shiny Artist Time™ with your latest game project, and they come up with switches like this:

QMSliders.jpg

Note the non-standard metrics of the slide and the alpha halo surrounding the active area as particularly challenging obstacles to some kind of quick hack on the standard UISwitch. So we needed something custom to achieve the above. And here are the interesting looking UISwitch giblets we found for you to start with next time this kind of thing comes up:

CustomUISwitch found in homick/iPhone-Snippets is the one we ended up using; a kinda-close reimplementation of UISwitch behaviour, most notable exception being that it acts like a button with press triggering a slide animation, not the real UISwitch drag behaviour. But as the artist hadn’t provided an activated state for the slide, hey that actually solved a problem. Also it’s a bit odd that the author chose to create its own delegate for value changes, we had it just call [self sendActionsForControlEvents: UIControlEventValueChanged]; when appropriate, which fits nicely with Interface Builder’s control-drag default assignment for a UIControl.

If you’re looking for something that’s a really thorough and apparently exact behaving reimplementation of UISwitch, then we’d say that RCSwitch is probably your best starting point. Of course, that requires an actually appropriate set of component graphic pieces, as opposed to working off a superficial Photoshop mockup, so we went with expediency today.

An interesting alternative approach is UICustomSwitch which skins a UISlider instead of implementing off the UIControl base.

As a final treat, if you’d like to simply put a cute little icon on a regular switch’s slider, like this,

bellslider.jpg

and you’re not nervous about making assumptions about the internal view structure of standard controls, then DSSwitch is the little tidbit for you.

As always, if you have any other UISwitch tidbits to share, let us know!

Continue Reading →
4