5

I can change UISwitch's color with below code but always color is yellow how to change color to another color?

UISwitch *switch1=[[UISwitch alloc]initWithFrame:CGRectMake(70, 121, 94, 27)];
[switch1 setAlternateColors:YES];
  • possible duplicate of [change color of switch in iphone app](http://stackoverflow.com/questions/1720376/change-color-of-switch-in-iphone-app) – Fry Sep 19 '14 at 10:22

3 Answers3

29

Finally, with iOS5 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];

produce this

enter image description here

I hope this help !

Fry
  • 6,235
  • 8
  • 54
  • 93
2

Check this page for a project with a custom switch.

Iñigo Beitia
  • 6,303
  • 4
  • 40
  • 46
1

From the UISwitch reference, "The UISwitch class is not customizable." So you can't change the appearance of UISwitch.

taskinoor
  • 45,586
  • 12
  • 116
  • 142