UIProgressView可顯示正工作正在進行的進度,

此範例為點擊按鈕,並借助NSTimer去增加progress得值,

讓UIProgressView執行結束並跳出alertView提示user工作已完成。

viewController.m


#import "ViewController.h"

@interface ViewController ()

- (IBAction)toClick:(id)sender;
@property (strong, nonatomic) IBOutlet UIView *progressView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)toClick:(id)sender {
    
    [_progressView setHidden:NO];
    [_progressView setProgress:0.0f];
    
    [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(changeValue:) userInfo:nil repeats:YES];
}

-(void)changeValue:(id)sender
{
    [_progressView setProgress:_progressView.progress+0.1];
    
    if(_progressView.progress == 1){
        [sender invalidate];
        [_progressView setHidden:YES];
        
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"upload finish" message:nil delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
        [alertView show];
    }
    
}
@end

 

    文章標籤

    UIProgressView

    全站熱搜

    Will 發表在 痞客邦 留言(0) 人氣()