一、案例介绍:点击按钮upload,活动指示器转动,再次点击停止转动;点击download按钮进度条加载满后提示,如图01,图02。
图01图02
二、案例步骤:
1、选择Simple View Aplication,取名cq.31.活动指示器和进度条,如图03。
图03
2、Main.storyboard,如图04,图05。
图04图05
3、CQ31ViewController.h
#import <UIKit/UIKit.h> @interface CQ31ViewController : UIViewController { NSTimer *myTimer; } @property(nonatomic,strong) NSTimer *myTimer; @property (weak, nonatomic) IBOutlet UIActivityIndicatorView *myActivityIndicatorView; @property (weak, nonatomic) IBOutlet UIProgressView *myProgressView; - (IBAction)startToMove:(id)sender; - (IBAction)downloadProgress:(id)sender; @end
4、CQ31ViewController.m
#import "CQ31ViewController.h" @interface CQ31ViewController () @end @implementation CQ31ViewController @synthesize myTimer; - (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)startToMove:(id)sender { if ([self.myActivityIndicatorView isAnimating]) { [self.myActivityIndicatorView stopAnimating]; }else{ [self.myActivityIndicatorView startAnimating]; } } - (IBAction)downloadProgress:(id)sender { myTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(download) userInfo:nil repeats:YES]; } - (void)download { self.myProgressView.progress=self.myProgressView.progress+0.1; if (self.myProgressView.progress==1.0) { [myTimer invalidate]; UIAlertView*alert=[[UIAlertView alloc]initWithTitle:@"download completed!" message:@"" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; [alert show]; } } @end
iOS.UIKit.06.UIProgressView_UIActivityIndicatorView,布布扣,bubuko.com