View Full Version : Custom UISwitch
outl4nd3r
Jul 22, 2009, 10:42 AM
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 :o
robbieduncan
Jul 22, 2009, 11:46 AM
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 :o
In your subclass override drawRect: (http://developer.apple.com/iphone/library/documentation/uikit/reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instm/UIView/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: (http://developer.apple.com/iphone/library/documentation/uikit/reference/UISwitch_Class/Reference/Reference.html#//apple_ref/occ/instm/UISwitch/setOn:animated:). You might have to override this too (if you call it) to get the correct animation.
PhoneyDeveloper
Jul 22, 2009, 01:29 PM
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.
outl4nd3r
Jul 22, 2009, 02:05 PM
Thanks for replies!
I'll try both methods tonight.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.