//滑动条
UISlider* slider = [[UISlider alloc] initWithFrame:CGRectMake(50, 50, 220, 0)];
slider.continuous = YES;//是否随滑动时候变化
//最小值
[slider setMinimumValue:0.0];
//最大值
[slider setMaximumValue:10.0];
//当前值
[slider setValue:2.0 animated:YES];
//最小值图片
[slider setMinimumValueImage:[UIImage imageNamed:@"main_left_nav.png"]];
//最大值图片
[slider setMaximumValueImage:[UIImage imageNamed:@"main_right_nav.png"]];
// 最小值轨道图片
//[slider setMinimumTrackImage:[UIImage imageNamed:@"main_left_nav.png"] forState:UIControlStateNormal];
//最大值轨道图片
//[slider setMaximumTrackImage:[UIImage imageNamed:@"main_right_nav.png"] forState:UIControlStateNormal];
//最小值轨道颜色
[slider setMinimumTrackTintColor:[UIColor redColor]];
//最大值轨道颜色
[slider setMaximumTrackTintColor:[UIColor yellowColor]];
//设置滑块颜色
[slider setThumbTintColor:[UIColor clearColor]];
//设置滑块图片
[slider setThumbImage:[UIImage imageNamed:@"main_left_nav.png"] forState:UIControlStateNormal];
[slider setThumbImage:[UIImage imageNamed:@"main_left_nav.png"] forState:UIControlStateHighlighted];
//事件
[slider addTarget:self action:@selector(slider:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:slider];
//[slider release];
///获取 值
- (void)slider:(UISlider*)slider{
NSLog(@"%f",slider.value);
}
问题:
1、滑块大小:
滑块大小不能改变,但是能通过设置图片改变
- (void)setThumbImage:(nullable UIImage *)image forState:(UIControlState)state;
2、不能滑动,滑动没反应
需要设置宽高!:宽度不仅是表示宽度,也表示触摸的宽度;而高度只表示触摸的高度。
高度设置为0,当然无法滑动。