TFSliderView 是一个易于使用的漂亮切换按钮,适用于 iOS 8+,基于 POP 动画框架构建。我将其编写在一起以供内部项目使用,并在认为其他人可能需要类似功能时将其共享。
platform :ios, '8.0'
pod "TFSliderView", "~> 0.1.0"
TFSliderView 非常简单易用。只需像下面这样程序性地创建一个视图,然后调用切换代理方法,以便在视图切换时执行所需的操作。
//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]
添加通用起始值