首页 > 代码库 > UISlider控件

UISlider控件

用处:在一个连续的区间中选择一个值

-(void)viewDidLoad

{

  [super viewDidLoad];

  CGRect frame = CGRectMake(20,20,200,0);

      self.slider = [[UISlider alloc]initWithFrame:frame];

      //设置最小值

      self.slider.minimumValue = http://www.mamicode.com/0;

      //设置最大值

  self.slider.maximumValue = http://www.mamicode.com/100;

  //设置当前值

  self.slider.value = http://www.mamicode.com/50;

  //是否连续触发事件处理

  self.slider.continuous = YES;

  //最小端颜色

  self.slider.minimumTrackTintColor = [UIColor redColor];

  //最大段颜色

   self.slider.maximumTrackTintColor = [UIColor greenColor];

      //滑块颜色

      self.slider.thumbTintColor = [UIColor blackColor];

      //添加值改变事件方法

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

      [self.view addSubView:self.slider];

}

-(IBAction) change:(id)sender

{

   UISlider * slider  = (UISlider*)sender;

  float value = http://www.mamicode.com/slider.value;

  NSLog(@"%f",value);

}