UIProgressView[进度条][一般型];UIStepper步数器][事件驱动型]

时间:2023-03-09 14:56:01
UIProgressView[进度条][一般型];UIStepper步数器][事件驱动型]

//
//  ViewController.m
//  ProgressAndSteper
//
//  Created by hehe on 15/9/21.
//  Copyright (c) 2015年 wang.hehe. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    float w = self.view.bounds.size.width;
    float h = self.view.bounds.size.height;
    NSLog(@"宽=%.1f,高=%.1f",w,h);

[self creatProgress];
    
    [self createSteper];
}

#pragma mark    --------------------进度条
- (void)creatProgress
{
    UIProgressView *pv = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
    
    pv.frame = CGRectMake(75, 50, 299, 50);
    
    [self.view addSubview:pv];
    
    pv.progress = 0.3;
    
    pv.tintColor = [UIColor orangeColor];
    
    pv.progressTintColor = [UIColor redColor];
    
    pv.tag = 10;
    pv.trackTintColor = [UIColor yellowColor];
}

#pragma mark    ------------------------步数器
- (void)createSteper
{
    UIStepper *step = [[UIStepper alloc] initWithFrame:CGRectMake(100, 120, 100, 50)];
    [self.view addSubview:step];
    
    step.stepValue = 3;
    step.minimumValue = 0;
    step.maximumValue = 20;
    
    step.value = 0;
    
    step.tintColor = [UIColor greenColor];
    
    step.wraps = YES;
    
    step.continuous = YES;
    
    step.autorepeat = NO;
    
    [step addTarget:self action:@selector(onStep:) forControlEvents:UIControlEventValueChanged];
}

- (void)onStep:(UIStepper *)step
{
    UIProgressView *pv = (id)[self.view viewWithTag:10];
    
    pv.progress = step.value/20;
    NSLog(@"step = %f",step.value);
}
@end
UIProgressView[进度条][一般型];UIStepper步数器][事件驱动型]