1 #import "ViewController.h" 2 #import "ViewController2.h" 3 4 @interface ViewController () 5 6 @end 7 8 @implementation ViewController 9 10 @synthesize slider = _slider; 11 @synthesize pView = _progressView; 12 13 - (void)viewDidLoad { 14 [super viewDidLoad]; 15 16 _progressView = [[UIProgressView alloc]init]; 17 18 //进度条的x ,y 宽都可以改变,高不可以变 19 _progressView.frame = CGRectMake(50, 100, 200, 600); 20 21 //进度条的颜色 22 _progressView.tintColor=[UIColor redColor]; 23 24 _progressView.progress=0.5; 25 26 // 27 //设置进度条的风格 28 _progressView.progressViewStyle = UIProgressViewStyleDefault; 29 30 [self.view addSubview:_progressView]; 31 32 33 34 _slider = [[UISlider alloc] init]; 35 36 _slider.frame = CGRectMake(50, 200, 200, 10); 37 38 _slider.maximumValue = 1000; 39 //最小值可以是负值 40 _slider.minimumValue = 0; 41 42 //_slider.value = 0.5; 43 44 //左侧滑条的颜色 45 _slider.minimumTrackTintColor = [UIColor grayColor]; 46 //右侧滑条颜色 47 _slider.maximumTrackTintColor = [UIColor greenColor]; 48 49 //滑块颜色 50 _slider.thumbTintColor = [UIColor redColor]; 51 52 [_slider addTarget:self action:@selector(slided) forControlEvents:UIControlEventValueChanged]; 53 54 [self.view addSubview:_slider]; 55 56 57 } 58 59 -(void)slided 60 { 61 _progressView.progress = (_slider.value-_slider.minimumValue)/(_slider.maximumValue-_slider.minimumValue); 62 NSLog(@"value = %f",_slider.value); 63 }
1 @interface ViewController : UIViewController 2 { 3 //定义一个进度条 4 UIProgressView* _progressView; 5 6 //滑动条 7 UISlider* _slider; 8 9 } 10 11 @property(retain,nonatomic) UIProgressView* pView; 12 13 @property(retain,nonatomic) UISlider* slider;
时间: 2024-10-09 22:55:19