IOS UIProgressView 用法
UIProgressView:
作用:
动态显示当前工作状态进度。
progressView
Progress bar view
1.h file
// Created by denny chen on 12-7-8.
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ProgressViewViewController : UIViewController
{
UIProgressView *progressview;
UIProgressView *barprogressview;
NSTimer *timer;
IBOutlet UIButton *startButton;
IBOutlet UIButton *stopButton;
}
@property (nonatomic,retain) IBOutlet UIProgressView *progressview;
@property (nonatomic,retain) IBOutlet UIProgressView *barprogressview;
-(IBAction) startProgress:(id)sender;
-(IBAction) stopProgress:(id)sender;
@end
2 .m file
@implementation ProgressViewViewController
@synthesize progressview;
@synthesize barprogressview;
- (void)viewDidLoad
{
self.progressview=nil;
self.barprogressview=nil;
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
stopButton.enabled = NO;
startButton.enabled = YES;
}
-(void) dealloc
{
self.progressview=nil;
self.barprogressview=nil;
[super dealloc];
}
- (void)viewDidUnload
{
self.progressview=nil;
self.barprogressview=nil;
[super viewDidUnload];
// Release any retained subviews of the main view.
}
/*进度条每次加0.01 */
-(void) timerChanged:(id)sender
{
self.progressview.progress +=0.01f;
self.barprogressview.progress +=0.01f;
}
-(IBAction) startProgress:(id)sender
{
timer=[NSTimer scheduledTimerWithTimeInterval:0.03f
target:self
selector:@selector(timerChanged:)
userInfo:nil
repeats:YES];
//[timer retain];
startButton.enabled = NO;
stopButton.enabled = YES;
}
-(IBAction) stopProgress:(id)sender
{
[timer invalidate];
//[timer release];
//timer =nil;
self.progressview.progress=0.0f;
self.barprogressview.progress=0.0f;
startButton.enabled = YES;
stopButton.enabled = NO;
}
3 run reslut