iOS 复习笔记 UISlider基础篇(一)

来源:互联网 发布:中科院虹膜数据库 编辑:程序博客网 时间:2024/05/16 04:36
@porperty

1、value

 --这个值是介于滑块的最大值和最小值之间的,如果没有设置边界值,默认为0-1;

2、minimumValue
 --设置滑块最小边界值(默认为0)

3、maximumValue
 --设置滑块最大边界值(默认为1)

4、minimumValueImage

 --设置滑块最左端显示的图片
5、maximumValueImage
 --设置滑块最右端显示的图片

6、continuous(Bool)

 --设置滑块是否连续变化(默认为YES)

7、minimumTrackTintColor

 --设置滑块左边(小于部分)线条的颜色

8、maximumTrackTintColor
 --设置滑块右边(大于部分)线条的颜色

9、thumbTintColor

 --设置滑块颜色(影响已划过一端的颜色),注意这个属性:如果你没有设置滑块的图片,那个这个属性将只会改变已划过一段线条的颜色,不会改变滑块的颜色,如果你设置了滑块的图片,又设置了这个属性,那么滑块的图片将不显示,滑块的颜色会改变。


@method

手动设置滑块的值:

- (void)setValue:(float)value animated:(BOOL)animated;

设置滑块的图片:

- (void)setThumbImage:(UIImage *)image forState:(UIControlState)state;

设置滑块划过部分的线条图案

- (void)setMinimumTrackImage:(UIImage *)image forState:(UIControlState)state;

设置滑块未划过部分的线条图案

- (void)setMaximumTrackImage:(UIImage *)image forState:(UIControlState)state;

对应的几个get方法

- (UIImage *)thumbImageForState:(UIControlState)state;
- (UIImage *)minimumTrackImageForState:(UIControlState)state;
- (UIImage *)maximumTrackImageForState:(UIControlState)state;

@extension

在用到UISlider时发现无法通过改变frame来改变高度,这时看到类中有一个方法

// lets a subclass lay out the track and thumb as needed 

- (CGRect)minimumValueImageRectForBounds:(CGRect)bounds; - (CGRect)maximumValueImageRectForBounds:(CGRect)bounds; - (CGRect)<span style="color:#ff0000;">trackRectForBounds</span>:(CGRect)bounds;  

这个方法直接调用是无效的,于是重写一个继承UISlider的类UISliderCustomH,在子类中重写

@implementation UISliderCustomH- (CGRect)trackRectForBounds:(CGRect)bounds{    return CGRectMake(0, 0, SCREEN_WIDTH - 120, 10);}@end
[self.shtterSlider setThumbImage:[UIImage imageNamed:@"control_bar_seek_btn"] forState:0];
self.shtterSlider.minimumTrackTintColor = UniColor(252, 174, 13);self.shtterSlider.maximumTrackTintColor = [UIColor lightGrayColor];







1 0