IOS-UIProgressView和UIActivityIndicatorView

来源:互联网 发布:维氏硬度计软件 编辑:程序博客网 时间:2024/04/19 08:34

UIProgressView

       一个进度条,一般用来量化一个耗时的工作,指示当前工作的进度。

UIActivityIndicatorView

      一个等待示意控件,用来表示当前的工作还没结束,需要继续等待。

示例

h文件
////  ViewController.h//  1129_HelloWolrd////  Created by God Lin on 14/11/29.//  Copyright (c) 2014年 arbboter. All rights reserved.//#import <UIKit/UIKit.h>@interface ViewController : UIViewController{    IBOutlet UITextField* _textTime;    IBOutlet UIProgressView* _procssUpdate;    IBOutlet UIButton* _buttonUpdate;    IBOutlet UIActivityIndicatorView* _indicatorUpdate;    NSTimer* _timerUpdate;}@property (nonatomic, retain) UITextField* _textTime;@property (nonatomic, retain) UIProgressView* _procssUpdate;@property (nonatomic, retain) UIActivityIndicatorView*_indicatorUpdate;@property (nonatomic, retain) UIButton* _buttonUpdate;-(IBAction)onTextFieldEnd:(id)sender;-(IBAction)onClickUpdate:(id)sender;@end


m文件
////  ViewController.m//  1129_HelloWolrd////  Created by God Lin on 14/11/29.//  Copyright (c) 2014年 arbboter. All rights reserved.//#import "ViewController.h"@interface ViewController ()@end@implementation ViewController@synthesize _textTime;@synthesize _indicatorUpdate;@synthesize _procssUpdate;@synthesize _buttonUpdate;-(IBAction)onTextFieldEnd:(id)sender{    [_textTime resignFirstResponder];}- (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)onClickUpdate:(id)sender{    // 正在更新    if(_indicatorUpdate.isAnimating)    {        [_indicatorUpdate stopAnimating];        _procssUpdate.progress = 0.0f;        [_timerUpdate invalidate];        [_buttonUpdate setTitle:@"Update" forState:UIControlStateNormal];    }    // 还没开始更新    else    {        [_indicatorUpdate startAnimating];        _procssUpdate.progress = 0.0f;        _timerUpdate = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateProcess) userInfo:nil repeats:YES];        [_buttonUpdate setTitle:@"Stop" forState:UIControlStateNormal];    }}-(void)updateProcess{    // 修改进度条    if(_procssUpdate.progress < 1.0)    {        _procssUpdate.progress += rand()%10/100.0f;    }    else    {        [self onClickUpdate:nil];    }    NSString* strProcess = [[NSString alloc] initWithFormat:@"更新进度:%.2f%%", _procssUpdate.progress * 100 ];    _textTime.text = strProcess;    [strProcess release];}-(void)dealloc{    [_textTime release];    [_buttonUpdate release];    [_indicatorUpdate release];    [_procssUpdate release];    [super dealloc];}@end


运行效果图

0 0
原创粉丝点击