progress的简单使用


progress的简单使用
 .h文件

#import <UIKit/UIKit.h>

@interface ProgressViewController : UIViewController
{
    UIProgressView * progressview;
    UIProgressView * barprogressview;
    
    UIButton * startBtn;
    UIButton * stopBtn;
    
    NSTimer *timer;//定时器
}

@property(retain, nonatomic) IBOutlet UIProgressView * progressview;
@property(retain, nonatomic) IBOutlet UIProgressView * barprogressview;
@property(retain, nonatomic) IBOutlet UIButton * startBtn;
@property(retain, nonatomic) IBOutlet UIButton * stopBtn;

-(IBAction)startProgress:(id)sender;
-(IBAction)stopProgress:(id)sender;

@end

 .m文件

#import "ProgressViewController.h"



@interface ProgressViewController ()

@end

@implementation ProgressViewController

@synthesize progressview;
@synthesize barprogressview;
@synthesize startBtn;
@synthesize stopBtn;

-(void)dealloc{
    
    self.progressview=nil;
    self.barprogressview=nil;
    
    [super dealloc];
}


- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

-(void) timeChanged:(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(timeChanged:)//调用进度改变的方法
                                           userInfo:nil 
                                           repeats:YES];
//    [timer release];
}
//停止进度条
-(IBAction)stopProgress:(id)sender
{
    [timer invalidate];//使Timer失效
     timer=nil;//注意这一句的位置,不要放到release后,否则会报错的
    [timer release];

    self.progressview.progress=0.0f;
    self.barprogressview.progress=0.0f;
}

@end
 

你可能感兴趣的:(progress)