iOS7 style drop in replacement for UISwitch
If you're using SevenSwitch
in an app or for some other reason consider throwing me some coin.
1GuFb1y7xEmKiD6XD3tGEJBriYJ2hXp8zY
To use it, add SevenSwitch.h and SevenSwitch.m files to your project and add the QuartzCore framework to your project.
Initializing and adding the switch to the screen
SevenSwitch *mySwitch = [[SevenSwitch alloc] initWithFrame:CGRectMake(10, 10, 50, 30)];
[self.view addSubview:mySwitch];
When the user manipulates the switch control ("flips" it) a UIControlEventValueChanged
event is generated.
[mySwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
You can set images for the on/off states
mySwitch.offImage = [UIImage imageNamed:@"cross.png"];
mySwitch.onImage = [UIImage imageNamed:@"check.png"];
You can also customize the switches colors
mySwitch.thumbTintColor = [UIColor colorWithRed:0.19f green:0.23f blue:0.33f alpha:1.00f];
mySwitch.activeColor = [UIColor colorWithRed:0.07f green:0.09f blue:0.11f alpha:1.00f];
mySwitch.inactiveColor = [UIColor colorWithRed:0.07f green:0.09f blue:0.11f alpha:1.00f];
mySwitch.onTintColor = [UIColor colorWithRed:0.45f green:0.58f blue:0.67f alpha:1.00f];
mySwitch.borderColor = [UIColor clearColor];
mySwitch.shadowColor = [UIColor blackColor];
You can resize the switch frame to whatever you like to make fatter/skinnier controls
mySwitch.frame = CGRectMake(0, 0, 100, 50);
You can turn off the rounded look by setting the isRounded
property to NO
mySwitch.isRounded = NO;
SevenSwitch requires iOS 5.0 and above.
SevenSwitch uses ARC as of its 1.0 release.
Made available under the MIT License. Attribution would be nice.