//自己定义UISlider的样式和滑块

//轨道图片

UIImage *stetchLeftTrack = [UIImage
imageNamed:@"thick"];

UIImage *stetchRightTrack = [UIImage
imageNamed:@"thick"];

//滑块图片

UIImage *thumbImage = [UIImage
imageNamed:@"thumb"];

//创建slider

UISlider *slider = [[UISlider
,
, , )];

slider.backgroundColor = [UIColor
clearColor];

slider.value =
1.0;

slider.minimumValue =
0.5;

slider.maximumValue =
1.0;

//设置轨道的图片

[slider setMinimumTrackImage:stetchLeftTrack
forState:UIControlStateNormal];

[slider setMaximumTrackImage:stetchRightTrack
forState:UIControlStateNormal];

//设置滑块的图片

//[slider setThumbImage:thumbImage forState:UIControlStateHighlighted];

[slider setThumbImage:thumbImage
forState:UIControlStateNormal];

//滑动滑块加入事件

//滑动过程中不断触发事件

[slider addTarget:self
action:@selector(onThumb:)
forControlEvents:UIControlEventValueChanged];

//滑动完毕加入事件

//滑动完毕后触发事件

[slider addTarget:self
action:@selector(endThumb:)
forControlEvents:UIControlEventTouchUpInside];

[self
addSubview:slider];


05-11 01:27