一个类似 UISegmentedControl 的自定义组件,具有高度可定制性。
您可以通过在 Podfile 中添加 STTimeSlider
来使用 CocoaPods。如果您不想使用此方法,请参阅以下方法
请包含以下 4 个文件
STTimeSlider.h
STTimeSlider.m
STTimeSliderModeView.h
STTimeSliderModeView.m
并包含 QuartzCore.framework
和 CoreGraphics.framework
。
此插件具有高度可定制性。您可以自定义
STTimeSliderMode mode
:滑块的模式(多选或单选)int startIndex
:在 STTimeSliderModeMulti
模式下,它是初始出发点float numberOfPoints
:点的数量(多于 1)float radiusPoint
:(1)点的半径float heightLine
:(2)两个点之间的高度。高度必须小于 radiusPoint * 2
;float spaceBetweenPoints
:(3)两点之间的空间float radiusCircle
:(4)选中超圈内部的点半径CGGradientRef gradient
:背景条的渐变CGGradientRef gradientForeground
:前景条的渐变UIColor *strokeColor
:背景条描边的颜色。float strokeSize
:背景条描边的大小。UIColor *strokeColorForeground
:前景条描边的颜色。float strokeSizeForeground
:前景条描边的大小。CGSize shadowSize
:大小。float shadowBlur
:模糊度。UIColor *shadowColor
:颜色。构建并运行 Xcode 中的 STTimeSliderExample 项目,以查看 STTimeSlider
的操作。
STTimeSlider *timeSlider = [[STTimeSlider alloc] initWithFrame:CGRectMake(5.0, 5.0, 310.0, 110.0)];
[timeSlider setDelegate:self];
[self.view addSubview:timeSlider];
别忘了在您的 ViewController 中实现 STTimeSliderDelegate
协议。没有它,您将无法检测到用户更改索引
- (void)timeSlider:(STTimeSlider *)timeSlider didSelectPointAtIndex:(int)index {
NSLog(@"User clicked on TimeSlider %@ at Index %d", timeSlider, index);
}
或当滑块发生变化时
- (void)timeSlider:(STTimeSlider *)timeSlider didMoveToPointAtIndex:(int)index {
NSLog(@"TimeSlider %@ has changed at Index %d", timeSlider, index);
}
您可以使用 - (void)moveToIndex:(int)index;
改变滑块的索引。
Sebastien Thiebaud
STTimeSlider 在MIT许可证下可用。