Reputation: 1179
I want to make custom UISwitch for project. I want to change text as well as background.
I gone through multiple posts on stack-overflow for this. Some where just image drawing or core graphics drawing. I don't want both of them as they are not sufficient.
But I need a single code which will be sufficient for iOS 4.2 as well as iOS 6.0.
Upvotes: 1
Views: 1561
Reputation: 9913
Use this to change the background color . This changes the off color for UISwitch control
// Set the tint color for the On state. Here we set green colour tint for On state
[customizedSwitch setOnTintColor:[UIColor colorWithRed:64.0/255 green:128.0/255.0 blue:64.0/255.0 alpha:1.0]];
// Set the tint color for the Off state. Here we set green red tint for Off state
[customizedSwitch setTintColor:[UIColor colorWithRed:255.0/255 green:128.0/255.0 blue:128.0/255.0 alpha:1.0]];
// Set the tint color for the round shaped Thumb. Here we set blue tint for the Thumb
[customizedSwitch setThumbTintColor:[UIColor colorWithRed:64.0/255 green:64.0/255.0 blue:255.0/255.0 alpha:1.0]];
Note : To modify the private view hierarchy of framework controls is absolutely unsupported, and can cause incompatibility with OS updates if you try to change text using subviews of uiswitch.
Use this nice tutorial for both these tasks: customizing-user-interface-uiswitch Hope it helps you.
Upvotes: 2
Reputation: 11724
Whenever I need some open-source component, I go to cocoacontrols : maybe this one https://www.cocoacontrols.com/controls/ssswitch (I haven't tried...)
Upvotes: 1