一、简介
<<UISlider是一个方便的控件,让用户能够以可视化的方式设置指定范围内的值。和按钮一样,滑块也能响应事件,还可像文本框一样被读取。如果希望用户对滑块的调整立刻影响应用程序,则需要让他触发操作
<<继承关系:UISlider-->UIControl-->UIView-->UIResponder-->NSObject
格式为
1-->设置当前值(作用)
slider.value = 50; (这是具体的例子)
@property(nonatomic) float value; // 默认是 0.0.这个值将被固定在min/max上。(这是说明)
二、UISlider的属性(属性的顺序与苹果API一致)
1--> 设置当前值
slider.value = 50;
@property(nonatomic) float value; // 默认是 0.0.这个值将被固定在min/max上。
2-->设置最小值
slider.minimumValue = 0.0;
@property(nonatomic) float minimumValue; // 当值可以改变时,滑块可以滑动到最小位置的值,默认为0.0
3-->设置最大值
slider. maximumValue = 100;
@property(nonatomic) float maximumValue; // 当值可以改变时,滑块可以滑动到最大位置的值,默认为1.0
4-->设置最小值一端图片,会挤压滑动条宽度
slider.minimumValueImage = [UIImage imageNamed:@"001.jpeg"];
@property(nullable, nonatomic,strong) UIImage *minimumValueImage; //滑块条最小值处设置的图片,默认为nil
5-->设置最大值一端图片,会挤压滑动条宽度
slider.maximumValueImage=[UIImage imageNamed:@"2.png"];
@property(nullable, nonatomic,strong) UIImage *maximumValueImage; //滑块条最大值处设置的图片,默认为nil
6--> 设置是否可连续变化
[slider setContinuous:YES];
@property(nonatomic,getter=isContinuous) BOOL continuous; // 默认值为YES设置为YES只要滑轮滚动就会触发change方法设置为NO只有当滑轮停止移动时才会触发change方法
7-->设置已经滑过一端滑动条颜色
slider.minimumTrackTintColor=[UIColor redColor];
@property(nullable, nonatomic,strong) UIColor *minimumTrackTintColor//小于滑块当前值滑块条的颜色,默认为蓝色
8-->设置未滑过一端滑动条颜色
slider.maximumTrackTintColor=[UIColor blackColor];
@property(nullable, nonatomic,strong) UIColor *maximumTrackTintColor//大于滑块当前值滑块条的颜色,默认为白色
9-->设置滑块颜色
slider.thumbTintColor=[UIColor yellowColor];
@property(nullable, nonatomic,strong) UIColor *thumbTintColor// 当前滑块的颜色,默认为白色
10-->设置slider的值
[slider setValue:3 animated:YES];
- (void)setValue:(float)value animated:(BOOL)animated;
11-->设置滑块图片背景
[sli1 setThumbImage:[UIImage imageNamed:@"1.png"] forState:UIControlStateNormal];
- (void)setThumbImage:(nullable UIImage *)image forState:(UIControlState)state;
12-->设置已经滑过一端滑动条背景图片,会覆盖之前设置的颜色
[sli1 setMinimumTrackImage:[UIImage imageNamed:@"3.png"] forState:UIControlStateNormal];
- (void)setMinimumTrackImage:(nullable UIImage *)image forState:(UIControlState)state;
13-->设置未滑过一端滑动条背景图片
[sli1 setMaximumTrackImage:[UIImage imageNamed:@"logo.png"] forState:UIControlStateNormal];
- (void)setMaximumTrackImage:(nullable UIImage *)image forState:(UIControlState)state;
14-->获取滑块的图片
UIImage *image=[slider thumbImageForState:UIControlStateNormal];
-(nullable UIImage *)thumbImageForState:(UIControlState)state;
15-->获取滑块划过部分的线条图案
UIImage *image=[slider minimumTrackImageForState:UIControlStateNormal];
-(nullable UIImage *)minimumTrackImageForState:(UIControlState)state;
16-->获取滑块未划过部分的线条图案
UIImage *image=[slider maximumTrackImageForState:UIControlStateNormal];
- (nullable UIImage *)maximumTrackImageForState:(UIControlState)state;
17-->获取当前滑块的图片
UIImage *image=[slider currentThumbImage];
@property(nullable,nonatomic,readonly) UIImage *currentThumbImage;
18-->获取滑块条最小值处设置的图片
UIImage *image=[slider currentMinimumTrackImage];
@property(nullable,nonatomic,readonly) UIImage *currentMinimumTrackImage;
19--> 滑块条最大值处设置的图片
UIImage *image=[slider currentMaximumTrackImage];
@property(nullable,nonatomic,readonly) UIImage *currentMaximumTrackImage;
20-->设置滑块最小值
- (CGRect)minimumValueImageRectForBounds:(CGRect)bounds
{
return CGRectMake(0, 0, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame));
}
-(CGRect)minimumValueImageRectForBounds:(CGRect)bounds;
21-->设置滑块最大值
-(CGRect)maximumValueImageRectForBounds:(CGRect)bounds
{
return CGRectMake(0, 0, CGRectGetWidth(self.frame)/ 2, CGRectGetHeight(self.frame) / 2);
}
-(CGRect)maximumValueImageRectForBounds:(CGRect)bounds;
22-->控制slider的宽和高,这个方法才是真正的改变slider滑道的高的
-(CGRect)trackRectForBounds:(CGRect)bounds
{
return CGRectMake(0, 0, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame));
}
-(CGRect)trackRectForBounds:(CGRect)bounds;
23-->改变滑块的触摸范围
-(CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:(float)value
{
return CGRectInset([super thumbRectForBounds:bounds trackRect:rect value:value], 10, 10);
}
-(CGRect)thumbRectForBounds:(CGRect)bounds trackRect:(CGRect)rect value:(float)value;
备注:slider上的那个滑动的圆圈的大小是没有办法进行改变的,并且,重写这四个方法,可以改变,没有办法把圆圈滑到两端的问题