//左右轨的图片
UIImage *stetchLeftTrack = [UIImage imageNamed:@"snow_bar.png"];
UIImage *stetchRightTrack = [UIImage imageNamed:@"sun_bar.png"];
//滑块图片
UIImage *thumbImage = [UIImage imageNamed:@"mark.png"];
UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(30,320,257,7)];
slider.backgroundColor = [UIColor clearColor];
slider.value = 1.0;
slider.minimumValue = 0.7;
slider.maximumValue = 1.0;
//设置背景图片
[slider setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
[slider setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];
//注意这里务必加上UIControlStateHightlighted的状态,否则当拖动滑块时滑块将变成原生的控件
[slider setThumbImage:thumbImage forState:UIControlStateHighlighted];
[slider setThumbImage:thumbImage forState:UIControlStateNormal];
//滑块拖动时的事件
[slider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
//滑块拖动后的事件
[slider addTarget:self action:@selector(sliderDragUp:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:slider];
其中绑定事件函数的返回值必须为IBAction,
- (IBAction) SliderValue:(id)sender