Custom UISwitch

Discussion in 'iOS Programming' started by outl4nd3r, Jul 22, 2009.

  1. outl4nd3r macrumors member

    Joined:
    Apr 6, 2008
    #1
    Hi,
    I have an app that has a fine wood background, I would like the controls to follow the same look and feel. So, I was wonder if there is a way to change the look of the UISwitch? I would like to make the control look like it was made of wood. I've found how to change the text but not the look.

    I'm thinking I have to create a subclass of UISwitch, but I can't think of the direction to go after that.

    Any help would be much appreciated. Thanks :eek:
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    In your subclass override drawRect:. You may well need to override other methods too if your switch does not draw in exactly the same place as the Apple one. Also not sure about setOn:animated:. You might have to override this too (if you call it) to get the correct animation.
     
  3. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #3
    There isn't that much to the UISwitch class. You might do just as well to start with an override of UIControl. There's no way to customize UISwitch using the public SDK methods.

    You'd need to do some mouse tracking and custom drawing of how you want your switch to look. You can easily add your own setOn property to make your switch similar to UISwitch.
     
  4. outl4nd3r thread starter macrumors member

    Joined:
    Apr 6, 2008
    #4
    Thanks for replies!

    I'll try both methods tonight.
     

Share This Page