ORBSwitch is a simple iOS-style switch with a few customization options:
- Squared or Rounded Pre-defined styles with colors customization;
- Custom style supporting any background and switch knob image;
- Controllable animation events and dynamic property changes;
ORBSwitch *squareSwitch = [[ORBSwitch alloc] initWithType:ORBSwitchSquare frame:CGRectMake(0, 0, 200, 120)];
ORBSwitch *roundSwitch = [[ORBSwitch alloc] initWithType:ORBSwitchRound frame:CGRectMake(0, 0, 200, 120)];
switch.knobColor = [UIColor orangeColor];
switch.inactiveBackgroundColor = [UIColor lightGrayColor];
switch.activeBackgroundColor = [UIColor darkGrayColor];
switch.delegate = (id<ORBSwitchDelegate>)self;
[self.view addSubview:switch];
ORBSwitch *customSwitch = [[ORBSwitch alloc] initWithCustomKnobImage:myKnobUIImage inactiveBackgroundImage:myOffStateBackgroundUIImage activeBackgroundImage:myOnStateBackgroundUIImage frame:CGRectMake(0, 0, 200, 120)];
customSwitch.delegate = (id<ORBSwitchDelegate>)self;
[self.view addSubview:customSwitch];
switch.knobRelativeHeight = 0.8f;
- (void)orbSwitchToggled:(ORBSwitch *)switchObj withNewValue:(BOOL)newValue {
NSLog(@"Switch toggled: new state is %@", (newValue) ? @"ON" : @"OFF");
}
- (void)orbSwitchToggleAnimationFinished:(ORBSwitch *)switchObj {
if (switchObj == _switch4) {
[switchObj setCustomKnobImage:[UIImage imageNamed:(switchObj.isOn) ? @"mario_l" : @"mario_r"]
inactiveBackgroundImage:[UIImage imageNamed:@"mario_bg"]
activeBackgroundImage:[UIImage imageNamed:@"mario_bg"]];
}
}
Distributed under the permissive zlib License