1、新建SingleViewApplication项目,拖两个button控件,一个ActiveIndicatorView控件,一个ProgressView控件,分别添加输出口和动作,添加方法不在累赘点击打开链接,点击第一个按钮,ActiveIndicatorView开始转动,再次点击停止,第二个按钮点击开始增加进度条,通过NSTimer控制定时增加,结束后弹窗,用了IOS8的UIAlertAction做了警告窗提示和操作表提示。
2、ViewController.m代码:
//
// ViewController.m
// TestProject
//
// Created by 侯家奇 on 16/8/17.
// Copyright © 2016年 侯家奇. All rights reserved.
//
#import "ViewController.h"
@interface ViewController () {
NSTimer *myTimer;
}
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *myActiveIndicatorView;
@property (weak, nonatomic) IBOutlet UIProgressView *myProgressView;
- (IBAction)startToMove:(id)sender;
- (IBAction)downloadProgress:(id)sender;
@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)startToMove:(id)sender {
if ([self.myActiveIndicatorView isAnimating]) {
[self.myActiveIndicatorView stopAnimating];
} else {
[self.myActiveIndicatorView 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.2;
if (self.myProgressView.progress == 1.0) {
[myTimer invalidate];
UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"download completed!" preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//按钮触发的方法
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"confirm" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//按钮触发的方法
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"clue" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//按钮触发的方法
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"contact" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//按钮触发的方法
}]];
[self presentViewController:alert animated:YES completion:nil];
}
}
@end
3、操作表提示,其实就改了一句,UIAlertAction做初始化,采用默认方式就是启动的操作表:
//
// ViewController.m
// TestProject
//
// Created by 侯家奇 on 16/8/17.
// Copyright © 2016年 侯家奇. All rights reserved.
//
#import "ViewController.h"
@interface ViewController () {
NSTimer *myTimer;
}
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *myActiveIndicatorView;
@property (weak, nonatomic) IBOutlet UIProgressView *myProgressView;
- (IBAction)startToMove:(id)sender;
- (IBAction)downloadProgress:(id)sender;
@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)startToMove:(id)sender {
if ([self.myActiveIndicatorView isAnimating]) {
[self.myActiveIndicatorView stopAnimating];
} else {
[self.myActiveIndicatorView 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.2;
if (self.myProgressView.progress == 1.0) {
[myTimer invalidate];
UIAlertController *alert = [[UIAlertController alloc] init];
[alert addAction:[UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//按钮触发的方法
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"confirm" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//按钮触发的方法
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"clue" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//按钮触发的方法
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"contact" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//按钮触发的方法
}]];
[self presentViewController:alert animated:YES completion:nil];
}
}
@end