UISlider UIProgressView

在ViewController.h中定义进度条和滑动条:

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d12f1b}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px 'Heiti SC Light'; color: #008400}p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #bb2ca2}span.s1 {font-variant-ligatures: no-common-ligatures}span.s2 {font-variant-ligatures: no-common-ligatures; color: #78492a}span.s3 {font-variant-ligatures: no-common-ligatures; color: #bb2ca2}span.s4 {font-variant-ligatures: no-common-ligatures; color: #703daa}span.s5 {font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures; color: #000000}span.s6 {font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures}span.s7 {font-variant-ligatures: no-common-ligatures; color: #000000}

#import 

@interface ViewController : UIViewController
{
    //进度条.用来表示下载、视频播放进度
    UIProgressView* _progressView;
    
    //滑动条,可以用来调整音量
    UISlider* _slider;
}

@property(retain,nonatomic) UIProgressView* pView;
@property(retain,nonatomic) UISlider* slider;

@end

在ViewController.m中:

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #bb2ca2}span.s1 {font-variant-ligatures: no-common-ligatures}span.s2 {font-variant-ligatures: no-common-ligatures; color: #000000}

@synthesize slider;
@synthesize pView;

1. 进度条UIProgressView

用来显示完成进度
在(void)ViewDidLoad中:

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #703daa}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008400}p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3d1d81}p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #4f8187}span.s1 {font-variant-ligatures: no-common-ligatures; color: #000000}span.s2 {font-variant-ligatures: no-common-ligatures; color: #4f8187}span.s3 {font-variant-ligatures: no-common-ligatures}span.s4 {font-variant-ligatures: no-common-ligatures; color: #3d1d81}span.s5 {font-variant-ligatures: no-common-ligatures; color: #703daa}span.s6 {font-variant-ligatures: no-common-ligatures; color: #272ad8}span.s7 {font-variant-ligatures: no-common-ligatures; color: #008400}span.s8 {font: 11.0px 'Heiti SC Light'; font-variant-ligatures: no-common-ligatures; color: #008400}span.s9 {font: 11.0px 'Heiti SC Light'; font-variant-ligatures: no-common-ligatures}span.s10 {font-variant-ligatures: no-common-ligatures; color: #bb2ca2}

    _progressView = [[UIProgressView alloc]init];
    _progressView.frame=CGRectMake(50, 100, 200, 40); //位置可变,进度条高度不可变
    
    //设置风格颜色
    _progressView.progressTintColor = [UIColor redColor];
    _progressView.trackTintColor=[UIColor blackColor];
    
    
    //设置风格特征
    _progressView.progressViewStyle = UIProgressViewStyleDefault;
    
    //设置进度条范围,从0-1
    _progressView.progress=0.5;
    
    
    
    [self.view addSubview:_progressView];
    

2. 滑动条 UISlider

在(void)ViewDidLoad中:

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3d1d81}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008400}p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #703daa}span.s1 {font-variant-ligatures: no-common-ligatures; color: #000000}span.s2 {font-variant-ligatures: no-common-ligatures; color: #4f8187}span.s3 {font-variant-ligatures: no-common-ligatures; color: #703daa}span.s4 {font-variant-ligatures: no-common-ligatures}span.s5 {font-variant-ligatures: no-common-ligatures; color: #3d1d81}span.s6 {font-variant-ligatures: no-common-ligatures; color: #272ad8}span.s7 {font-variant-ligatures: no-common-ligatures; color: #008400}span.s8 {font: 11.0px 'Heiti SC Light'; font-variant-ligatures: no-common-ligatures; color: #008400}span.s9 {font: 11.0px 'Heiti SC Light'; font-variant-ligatures: no-common-ligatures}span.s10 {font-variant-ligatures: no-common-ligatures; color: #bb2ca2}

 _slider=[[UISlider alloc]init];
    _slider.frame=CGRectMake(200, 50, 100, 40); //高度不可改
    
    //设置范围
    _slider.maximumValue=100;
    _slider.minimumValue=0; //可以是负的
    _slider.value=50;
    
    //整体风格颜色
    _slider.tintColor = [UIColor greenColor];
    //左侧颜色
    _slider.minimumTrackTintColor=[UIColor redColor];
    //右侧颜色
    _slider.maximumTrackTintColor=[UIColor blackColor];
    //滑块颜色
    _slider.thumbTintColor=[UIColor yellowColor];
    
    [self.view addSubview:_slider];

3.添加滑动条事件

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px 'Heiti SC Light'; color: #008400}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3d1d81}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; min-height: 13.0px}span.s1 {font: 11.0px Menlo; font-variant-ligatures: no-common-ligatures}span.s2 {font-variant-ligatures: no-common-ligatures}span.s3 {font-variant-ligatures: no-common-ligatures; color: #000000}span.s4 {font-variant-ligatures: no-common-ligatures; color: #4f8187}span.s5 {font-variant-ligatures: no-common-ligatures; color: #bb2ca2}

//添加事件函数
    [_slider addTarget:self action:@selector(pressSlider) forControlEvents:UIControlEventValueChanged];
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #4f8187}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d12f1b}span.s1 {font-variant-ligatures: no-common-ligatures}span.s2 {font-variant-ligatures: no-common-ligatures; color: #bb2ca2}span.s3 {font-variant-ligatures: no-common-ligatures; color: #000000}span.s4 {font-variant-ligatures: no-common-ligatures; color: #703daa}span.s5 {font-variant-ligatures: no-common-ligatures; color: #272ad8}span.s6 {font-variant-ligatures: no-common-ligatures; color: #008400}span.s7 {font: 11.0px 'Heiti SC Light'; font-variant-ligatures: no-common-ligatures; color: #008400}span.s8 {font-variant-ligatures: no-common-ligatures; color: #3d1d81}span.s9 {font-variant-ligatures: no-common-ligatures; color: #4f8187}

-(void)pressSlider
{
    _progressView.progress=_slider.value/100;  //进度条和滑动条同步变化
    NSLog(@"value=%f",_slider.value);
}

注意 此函数中的_progressView.progress=_slider.value/100; 可以使进度条和滑动条同步变化

你可能感兴趣的:(UISlider UIProgressView)