Change Color Of UISwitch Appwise


Answer :

Finally, with iOS 5 you can change the color of the switch with the property onTintColor.

UISwitch *s = [[UISwitch alloc] initWithFrame:CGRectMake(100, 100, 100, 100)]; s.on = YES; s.onTintColor = [UIColor redColor]; [self.view addSubview:s]; [s release]; 

produces this:

Enter image description here


For a global change for all UISwitch elements in Swift 3, use the appearance proxy:

UISwitch.appearance().onTintColor = UIColor.brown 

under the AppDelegate application:didFinishLaunchingWithOptions: method.


Currently you are limited to text values of On/Off or 0/1 for a UISwitch. You can customize the color by using tint. For further customization I would suggest something like what's been posted above going with a completely custom solution

ex. [mySwitch setOnTintColor:[UIColor colorWithRed:0 green:175.0/255.0 blue:176.0/255.0 alpha:1.0]];

source: http://www.raywenderlich.com/4344/user-interface-customization-in-ios-5

EDIT: For iOS3, you are limited to a custom implimentation, I would suggest swapping two buttons with custom images. In later iOS versions you are given much more control and built in customization options.


Comments

Popular posts from this blog

Chemistry - Bond Angles In NH3 And NCl3

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Change The Font Size Of Visual Studio Solution Explorer