Custom UISwitch to show YES / NO

You can see this in action in my free water tracking application "Hydrate Yourself". If this helped you please consider downloading it and leaving a review.

One of the great things about iPhone development are that there are lots of user interface pieces that are easy to put together and customize. Unfortunately there are also a lot of pieces which don't have all the basic customizations that may people want. The UISwitch is one of those.

Here is the standard UISwitch:

Its size, colors, and ON / OFF text are not changeable. Fortunately there are several great re-implementations (and a few hacks that use restricted API calls) to modify all this. One that I am using is the RCSwitch class available here.

I made two small changes to this code, first I renamed his RCSwitchOnOff class to RCSwitchYesNo and changed the labels to YES / NO. Second I added an init method to the RCSwitch.m base class which called the usual init function but provided the default frame size. This works fine since I am positioning the x and y coordinates using the "center" property:

The final result looks and behaves just like the original UISwitch, but is actually completely rewritten using the UIControl class. My switches now look like this:


  1. Thanks for the lists. There are a lot of these lists on different peoples blogs these days, most of they are just way out of date though – I look forward to delving deeper into this list and hopefully contributing to some quality blogs.

  2. Dear, I like your blog very much, I can get many useful information. Hope that we can communicate with each other. By the way, have you ever used memory card software ? Unfortunately I lost my memory card data. I do not know how to do.


Post a Comment

Popular posts from this blog

Using a JFileChooser to browse AWS S3

Novice to Coin Introduction

Taking Stuff Apart: Sony TC-800B Portable Reel-to-Reel Recorder