滑动条和进度条,滑动条是主动的,进度条是被动的。
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
// 进度条
UIProgressView* _uiProgressView;
// 滑动条
UISlider* _uiSlider;
}
@property (retain, nonatomic) UISlider* uiSlider;
@property (retain, nonatomic) UIProgressView* uiProgressView;
@end
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize uiProgressView = _uiProgressView;
@synthesize uiSlider = _uiSlider;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_uiProgressView = [[UIProgressView alloc] init];
// 进度条只有高度不能改变
_uiProgressView.frame = CGRectMake(90, 100, 200, 40);
// 范围 0 ~ 1
_uiProgressView.progress = 0.5;
// 进度的颜色
[_uiProgressView setTintColor:[UIColor redColor]];
_uiProgressView.progressTintColor = [UIColor greenColor];
// 整体进度的颜色
[_uiProgressView setTrackTintColor:[UIColor yellowColor]];
// 设置进度条风格
_uiProgressView.progressViewStyle = UIProgressViewStyleDefault;
[self.view addSubview:_uiProgressView];
_uiSlider = [[UISlider alloc] init];
_uiSlider.frame = CGRectMake(50, 200, 200, 40);
_uiSlider.maximumValue = 100;
_uiSlider.minimumValue = -100;
_uiSlider.value = 0;
// 滑块左侧的颜色
_uiSlider.minimumTrackTintColor = [UIColor grayColor];
// 滑块右侧的颜色
_uiSlider.maximumTrackTintColor = [UIColor redColor];
// 滑块的颜色
_uiSlider.thumbTintColor = [UIColor orangeColor];
[_uiSlider addTarget:self action:@selector(slideValue) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:_uiSlider];
}
- (void) slideValue {
NSLog(@"value = %f", _uiSlider.value);
_uiProgressView.progress = (_uiSlider.value + 100) / 200;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end