//UISlider触发的动作
-(void)sliderValueChanged:(id)sender{
UISlider *control = (UISlider *)sender;
if (control == mySlider) {
float value = control.value;
/*添加代码,对滑块的值做出响应*/
}
}
-(void)viewDidLoad{
/***********滑块控件UISlider**************/
//创建控件
UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(0, 0, 200, 0)];//高度可忽略
//设置控件范围, 默认为0.0--1.0
[slider setMinimumValue:0.0];
slider.maximumValue = 100.0;
//设置默认值
slider.value = 50.0;
//在控件一端显示图像
[slider setMinimumTrackImage:[UIImageimageNamed:@"min.png"] forState:UIControlStateNormal];//滑块可用状态 4种
[slider setMaximumTrackImage:[UIImageimageNamed:@"max.png"] forState:UIControlStateNormal];
//显示控件
[parentView addSubview: slider];//添加到父视图
self.navigationItem.titleView = slider;//添加到导航栏
//读取控件
float value = slider.value;
//滑块值变化时触发事件
[slider addTarget:selfaction:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
}