Xcode_7 iOS_9 ActiveIndicatorView_ProgressView_警告窗_操作表 控件 Objective-C (3)

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


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值