zoukankan      html  css  js  c++  java
  • iOS.UIKit.06.UIProgressView_UIActivityIndicatorView

    一、案例介绍:点击按钮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
  • 相关阅读:
    [Luogu 3794]签到题IV
    [JSOI 2015]最大公约数
    [BZOJ 5123][Lydsy1712月赛]线段树的匹配
    [BZOJ 5127][Lydsy1712月赛]数据校验
    [Codeforces Educational Round 71]Div. 2
    [NOIp 2018]all
    [BZOJ 2134]单选错位
    [hihoCoder 1384]Genius ACM
    [POJ 3233]Matrix Power Series
    [USACO 09FEB]Bullcow
  • 原文地址:https://www.cnblogs.com/cqchen/p/3764864.html
Copyright © 2011-2022 走看看