TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Oct 2015 |
Maintained by Tarik Fayad.
TFSliderView is an easy to use stylish toggle switch for iOS 8+ built on the POP animation framework. I put it together for use in an inhouse project and thought I'd share in case anyone else needed something similar.
platform :ios, '8.0'
pod "TFSliderView", "~> 0.1.0"
TFSliderView is very simple to use. Simply create a view programatcially (as shown below), and call the toggle delegate methods to do whatever it is you need to when the view toggles.
//Creating a frame for the slider that spans the width of the screen
CGRect frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 65.0f);
/*!Initializing the slider with a border color that matches the toggle color and left/right button images.
You can also set the animation constants here to change the ammount of spring and bounce that occurs as the
toggle shifts*/
TFSliderView *slider = [[TFSliderView alloc] initWithFrame:frame
borderColor:[UIColor tipiDarkGreen]
borderWidth:1.0f
toggleBackgroundColor:[UIColor tipiDarkGreen]
leftButtonImage:[UIImage imageNamed:@"comment-white"]
rightButtonImage:[UIImage imageNamed:@"filled-heart-green"]
springBounciness:5.0f
springSpeed:10.0f
andShouldInvertImages:YES];
/*!Overriding the default inverted images. If not overridden with something custom, the slider will
automatically invert the image colors as it toggles*/
slider.invertedLeftImage = [UIImage imageNamed:@"comment"];
slider.invertedRightImage = [UIImage imageNamed:@"outline-heart"];
//Setting the delegate
slider.delegate = self;
//Adding the slider to the View Controller's view
[self.view addSubview:slider];
#pragma mark - Slider Delegates
-(void)sliderViewDidToggleLeftOption:(TFSliderView *)sliderView
{
NSLog(@"Toggled Left");
}
- (void)sliderViewDidToggleRightOption:(TFSliderView *)sliderView
{
NSLog(@"Toggled Right");
}
[TFSliderView new]