iphone等待控件(UIActivityIndicatorView与UIProgressView)

UIActivityIndicatorView与UIProgressView

 如下图,当点击按钮是,等待控件运行。

                          iphone等待控件(UIActivityIndicatorView与UIProgressView)_第1张图片                  

 

UIActivityIndicatorView源码:

#import <UIKit/UIKit.h>

@interface UIActivityIndicatorViewController : UIViewController {
	UIActivityIndicatorView * myActivityView;
}

@property (nonatomic, retain) IBOutlet UIActivityIndicatorView * myActivityView;

-(IBAction)onClickButton: (id)sender;

@end



#import "UIActivityIndicatorViewController.h"

@implementation UIActivityIndicatorViewController

@synthesize myActivityView;

-(IBAction)onClickButton: (id)sender {
	if ([myActivityView isAnimating]) {
		[myActivityView stopAnimating];			
	} else {
		[myActivityView startAnimating];
	}
}


 

UIProgressView源码

#import <UIKit/UIKit.h>

@interface ProgressViewViewController : UIViewController {
	IBOutlet UIProgressView *Progress; 
	NSTimer *timer;
}

@property (nonatomic, retain) IBOutlet UIProgressView *Progress; 
@property (nonatomic, assign) NSTimer *timer;
	
-(IBAction)start;

@end
#import "ProgressViewViewController.h"

@implementation ProgressViewViewController

@synthesize  Progress;
@synthesize timer;

- (void)viewDidLoad {
    [super viewDidLoad];
}

-(IBAction)start{
	Progress.progress = 0.0;
	timer = [NSTimer 
			 scheduledTimerWithTimeInterval:1.0 
			 target:self 
			 selector:@selector(update) 
			 userInfo:nil repeats:YES];
}

-(void)update{
	Progress.progress = Progress.progress + 0.1;
	if (Progress.progress == 1.0) {
                  //操作  }
}


 

你可能感兴趣的:(iphone等待控件(UIActivityIndicatorView与UIProgressView))