Change color of UISwitch appwise

Ankit Sachan picture Ankit Sachan · Nov 12, 2009 · Viewed 22.4k times · Source

I am using UISwitch in iOS 3 to make a switch element in my app. It has default color set to blue, but I want to change its color to brown.

How can I choose a different color for the UISwitch element in iOS 3?

How can I choose a different color for the UISwitch element in a modern iOS app (iOS 5+)?

Answer

Fry picture Fry · Dec 10, 2011

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