Posts Tagged ‘ UISwitch ’


Changing the colour of a UISwitch control.

#define kSwitchOnColor [UIColor colorWithRed:0.647 green:0.757 blue:0.463 alpha:1] // /*#A5C176*/ Green

#define kSwitchOffColor [UIColor colorWithRed:0.29 green:0.29 blue:0.525 alpha:1]; // /*#4A4A86*/ Purple
UISwitch *switchview = [[UISwitch alloc] initWithFrame:CGRectZero];
[switchview setOn:TRUE animated:YES];
switchview.onTintColor = kSwitchOnColor;
switchview.tintColor = kSwitchOffColor;
//tintColor just does outline
switchview.backgroundColor = kSwitchOffColor;
switchview.layer.cornerRadius = 16.0f;

tintColor changes the background when sliding but when off just has the outline, if you change the background then it is square so add a corner radius.