//声明对象
@property (nonatomic,strong) UISlider *slider;
self.slider = [[UISlider alloc] init];
//设置属性
self.slider.backgroundColor = [UIColor grayColor];
self.slider.alpha = 0.8;
self.slider.frame = CGRectMake((self.view.frame.size.width-200)/2.0, self.view.frame.size.height/2.0, 200, 31);
//设置最小值
self.slider.minimumValue = 0.0f;
//设置最大值
self.slider.maximumValue = 1.0f;
//设置当前值
self.slider.value = 0.7f;
//设置滑过部分颜色
self.slider.minimumTrackTintColor = [UIColor blueColor];
//设置未滑过部分颜色
self.slider.maximumTrackTintColor = [UIColor whiteColor];
//设置thumb颜色
self.slider.thumbTintColor = [UIColor greenColor];
//设置minimumValueImage
[self.slider setMinimumValueImage:[UIImage imageNamed:@"min"]];
//设置maximumValueImage
[self.slider setMaximumValueImage:[UIImage imageNamed:@"max"]];
//前用于渲染滑块的最大轨迹图像
//[self.slider setMaximumTrackImage:[UIImage imageNamed:@"MaximumTrack"] forState:UIControlStateNormal];
//当前用于渲染滑块的最小轨迹图像
//[self.slider setMinimumTrackImage:[UIImage imageNamed:@"MinimumTrack"] forState:UIControlStateNormal];
//设置ThumbImage
//[self.slider setThumbImage:[UIImage imageNamed:@""] forState:UIControlStateSelected];
//滑块值更改是否生成连续的更新事件
self.slider.continuous = YES;
[self.slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
//设置属性
self.slider.backgroundColor = [UIColor grayColor];
self.slider.alpha = 0.8;
self.slider.frame = CGRectMake((self.view.frame.size.width-200)/2.0, self.view.frame.size.height/2.0, 200, 31);
//设置最小值
self.slider.minimumValue = 0.0f;
//设置最大值
self.slider.maximumValue = 1.0f;
//设置当前值
self.slider.value = 0.7f;
//设置滑过部分颜色
self.slider.minimumTrackTintColor = [UIColor blueColor];
//设置未滑过部分颜色
self.slider.maximumTrackTintColor = [UIColor whiteColor];
//设置thumb颜色
self.slider.thumbTintColor = [UIColor greenColor];
//设置minimumValueImage
[self.slider setMinimumValueImage:[UIImage imageNamed:@"min"]];
//设置maximumValueImage
[self.slider setMaximumValueImage:[UIImage imageNamed:@"max"]];
//前用于渲染滑块的最大轨迹图像
//[self.slider setMaximumTrackImage:[UIImage imageNamed:@"MaximumTrack"] forState:UIControlStateNormal];
//当前用于渲染滑块的最小轨迹图像
//[self.slider setMinimumTrackImage:[UIImage imageNamed:@"MinimumTrack"] forState:UIControlStateNormal];
//设置ThumbImage
//[self.slider setThumbImage:[UIImage imageNamed:@""] forState:UIControlStateSelected];
//滑块值更改是否生成连续的更新事件
self.slider.continuous = YES;
[self.slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:self.slider];
#pragma mark - 方法
- (void)sliderAction:(UISlider *)slider{
CGFloat value = self.slider.value;
NSLog(@"value %f",value);
- (void)sliderAction:(UISlider *)slider{
CGFloat value = self.slider.value;
NSLog(@"value %f",value);
}