DoubleThumbSlider
带有两个滑块的滑块控件。
双滑块控件
警告 !!
DTSlider 使用了 UISlider 类的私有 API,这会导致您的 App 被拒绝上传至 App Store。
DTSlider 使用了 UISlider 类中的私有 API,这将导致您的 App 被拒绝上传至 App Store。
预览效果图
使用方式
CocoaPods
pod 'DTSlider'
来源
将 DTSlider 文件夹拖入您的项目。
导入
#import "DTSlider.h"
// DTSlider.h
@interface DTSlider : UISlider
@property (nonatomic, assign) float maxValue;
@property (nonatomic, assign) float minValue;
- (void)setMinValue:(float)minValue animated:(BOOL)animated;
- (void)setMaxValue:(float)maxValue animated:(BOOL)animated;
- (void)setMinValue:(float)minValue maxValue:(float)maxValue animated:(BOOL)animated;
@end
创建实例
// in the other file.
DTSlider *slider = [[DTSlider alloc] init];
slider.maxValue = 100.0; // init value
slider.minValue = 0.0; // init value
[slider addTarget:self action:@selector(sender:event:) forControlEvents:UIControlEventValueChanged];
// selector
- (void)sender:(DTSlider *)sender event:(UIControlEvent)event {
NSLog(@"min value:%f\nmax value:%f\n", sender.minValue, sender.maxValue);
}
// set value without animation
slider.maxValue = 100.0;
slider.minValue = 0.0;
// set value with animation
[slider setMaxValue:100.0 animated:YES];
[slider setMinValue:1.0 animated:YES];
您可以像使用 UISlider 组件一样使用它,并通过 minValue
和 maxValue
属性设置值。同时,您还可以通过设置 target-action 来监听值改变的事件,并通过这两个属性获取新的值。父类中的 value
属性代表用户改变的值,这意味着 value
可能等于 minValue
或 maxValue
。
使用方法类似于系统自带的 UISlider,可以通过 minValue
和 maxValue
来设置控件的值。同时,可以通过设置 target-action 的方式来监听 ValueChanged 事件,并且通过这两个属性来获取到新的值。父类中的 value
属性表示用户改变的值,这意味着 value
可能等于 maxValue
或 minValue
。
许可证
MIT.