TFSliderView 0.1.1

TFSliderView 0.1.1

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最新发布2015年10月

Tarik Fayad 维护。




TFSliderView 是一个易于使用的漂亮切换按钮,适用于 iOS 8+,基于 POP 动画框架构建。我将其编写在一起以供内部项目使用,并在认为其他人可能需要类似功能时将其共享。

Podfile

platform :ios, '8.0'
pod "TFSliderView", "~> 0.1.0"

示例图像

TFSlider

使用方法

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] 添加通用起始值
  • 允许每个切换状态具有独特的颜色
  • 完成文档