`
jsntghf
  • 浏览: 2481126 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

进度条

    博客分类:
  • iOS
阅读更多

头文件:

 

#import <UIKit/UIKit.h>

@interface ThreadViewController : UIViewController {
	UIProgressView *threadProgressView;
	UIButton *threadStartButton;
	UILabel *label;
}

@property(nonatomic, retain) IBOutlet UIProgressView *threadProgressView;
@property(nonatomic, retain) IBOutlet UIButton *threadStartButton;
@property(nonatomic, retain) IBOutlet UILabel *label;

- (IBAction) startThreadButtonPressed:(UIButton *)sender;

@end

 

实现文件:

 

#import "ThreadViewController.h"

@implementation ThreadViewController

@synthesize threadProgressView, threadStartButton, label;

- (IBAction) startThreadButtonPressed:(UIButton *)sender {
	threadStartButton.hidden = YES;
	label.text = @"0";
	threadProgressView.progress = 0.0;
	[NSThread detachNewThreadSelector:@selector(startTheBackgroundJob) toTarget:self withObject:nil];
}

- (void) startTheBackgroundJob {
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
	[NSThread sleepForTimeInterval:0.5];
	[self performSelectorOnMainThread:@selector(makeMyProgressBarMoving) withObject:nil waitUntilDone:NO];
	[pool release];
}

- (void) makeMyProgressBarMoving {
	float actual = [threadProgressView progress];
	label.text = [NSString stringWithFormat:@"%.2f", actual];
	if (actual < 1) {
		threadProgressView.progress = actual + 0.01;
		[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(makeMyProgressBarMoving) userInfo:nil repeats:NO];
	}
	else threadStartButton.hidden = NO;
}

- (void)dealloc {
	[threadProgressView release];
	threadProgressView = nil;
	[threadStartButton release];
	threadStartButton = nil;
	[label release];
	label = nil;
	[super dealloc];
}

@end
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics