IBOutlet UIProgressView *progressview; int float = progressview.progress;
IBOutlet UIProgressView *progressview; [progressview setProgress:0.0];
- (IBAction)btnStart:(id)sender { [progress setProgress:0.0]; timer = [NSTimer scheduledTimerWithTimeInterval:0.10 target:self selector:@selector(setCustomProgress) userInfo:nil repeats:YES]; } - (void) setCustomProgress { progress.progress = progress.progress + 0.01; NSString *newValue = [[NSString alloc] initWithFormat:@"%.2f", progress.progress]; lblResult.text = newValue; if(progress.progress == 1.0) { lblResult.text = @"Load Finished!"; [timer invalidate]; } }
// // ViewController.h // progressViewApp // // Created by Weerachai on 11/10/55 BE. // Copyright (c) 2555 Weerachai. All rights reserved. // #import <UIKit/UIKit.h> @interface ViewController : UIViewController { IBOutlet UIProgressView *progress; IBOutlet UILabel *lblResult; NSTimer *timer; } - (IBAction)btnStart:(id)sender; - (void) setCustomProgress; @end
// // ViewController.m // progressViewApp // // Created by Weerachai on 11/10/55 BE. // Copyright (c) 2555 Weerachai. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (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)btnStart:(id)sender { [progress setProgress:0.0]; timer = [NSTimer scheduledTimerWithTimeInterval:0.10 target:self selector:@selector(setCustomProgress) userInfo:nil repeats:YES]; } - (void) setCustomProgress { progress.progress = progress.progress + 0.01; NSString *newValue = [[NSString alloc] initWithFormat:@"%.2f", progress.progress]; lblResult.text = newValue; if(progress.progress == 1.0) { lblResult.text = @"Load Finished!"; [timer invalidate]; } } - (void)dealloc { [progress release]; [lblResult release]; [super dealloc]; } @end
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท