iOS.UIKit.06.UIProgressView_UIActivityIndicatorView

一、案例介绍:点击按钮upload,活动指示器转动,再次点击停止转动;点击download按钮进度条加载满后提示,如图01,图02。

iOS.UIKit.06.UIProgressView_UIActivityIndicatorView图01iOS.UIKit.06.UIProgressView_UIActivityIndicatorView图02

二、案例步骤:

1、选择Simple View Aplication,取名cq.31.活动指示器和进度条,如图03。

iOS.UIKit.06.UIProgressView_UIActivityIndicatorView图03

2、Main.storyboard,如图04,图05。

iOS.UIKit.06.UIProgressView_UIActivityIndicatorView图04iOS.UIKit.06.UIProgressView_UIActivityIndicatorView图05

3、CQ31ViewController.h

iOS.UIKit.06.UIProgressView_UIActivityIndicatorView
#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
iOS.UIKit.06.UIProgressView_UIActivityIndicatorView

 

4、CQ31ViewController.m

iOS.UIKit.06.UIProgressView_UIActivityIndicatorView
#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

 

 

iOS.UIKit.06.UIProgressView_UIActivityIndicatorView,布布扣,bubuko.com

iOS.UIKit.06.UIProgressView_UIActivityIndicatorView

上一篇:64位ubuntu下Android开发环境的配置


下一篇:iOS: 属性列表介绍 Introduction to Property Lists