UIprogressView

UIProgressView 進度指示器

UIProgressView 與UIActivityIndicatorView 相似,只不過它提供了一個接口讓你可以顯示一個類似進度條的東西,這樣就能讓用戶知道當(dāng)前操作完成了多少(告知用戶離操作結(jié)束還多遠(yuǎn))。

一.創(chuàng)建

UIProgressView* progressView = [ [ UIProgressView alloc ]

initWithFrame:CGRectMake(150.0,20.0,130.0,30.0)];

二.設(shè)置風(fēng)格:

progressView .UIProgressViewStyle= UIProgressViewStyleDefault;

系統(tǒng)給你提供了2種風(fēng)格:

UIProgressViewStyleDefault 標(biāo)準(zhǔn)進度條

UIProgressViewStyleDefault 深灰色進度條,用于工具欄中

三.顯示

[ self.toolBar addSubview:progressView ];

四.進度

當(dāng)它顯示出來時你的程序可以更新它的進度,屬性progress是一個0.0到1.0之間的浮點數(shù):

progressView.progress= 0. 5;

五.示例代碼

4.09UIProgressView(1)

- (void)progressChanged:(NSTimer*)timer

{

if(_progressView.progress>=1.0) {

[timerinvalidate];

}

//如果對象的progress大于1.0,則定時器失效

_progressView.progress+=0.02;

//讓對象的progress值每次都加0.02,以此達到讓進度動起來的效果。

}

- (void)viewDidLoad

{

[superviewDidLoad];

self.progressView= [[UIProgressViewalloc]init];

//創(chuàng)建一個UIProgressView對象:_progressView

_progressView.frame=CGRectMake(0,20,320,0);

//設(shè)置它的位置及大小,它的高是默認(rèn)的為9,可以寫成0。

_progressView.progressViewStyle=UIProgressViewStyleDefault;

//設(shè)置它的風(fēng)格,為默認(rèn)的

_progressView.trackTintColor= [UIColorblueColor];

//設(shè)置軌道的顏色

_progressView.progressTintColor= [UIColorwhiteColor];

//設(shè)置進度的顏色

_progressView.progress=0.0;

//設(shè)置進度的初始值,即初始位置。范圍是0.0-1.0

[self.viewaddSubview:_progressView];

//把_progressView加入到view上

[_progressViewrelease];

//要記得release

[NSTimerscheduledTimerWithTimeInterval:0.5

target:self

selector:@selector(progressChanged:)

userInfo:nil

repeats:YES];

//設(shè)置定時器

}



第二種介紹

UIProgressView:

作用:

動態(tài)顯示當(dāng)前工作狀態(tài)進度。

progressView

Progress bar view

1.h file

//? Created by denny chen on 12-7-8.

//? Copyright (c) 2012年__MyCompanyName__. All rights reserved.

//

#import

@interfaceProgressViewViewController :UIViewController

{

UIProgressView*progressview;

UIProgressView*barprogressview;

NSTimer*timer;

IBOutletUIButton*startButton;

IBOutletUIButton*stopButton;

}

@property(nonatomic,retain)IBOutletUIProgressView*progressview;

@property(nonatomic,retain)IBOutletUIProgressView*barprogressview;

-(IBAction) startProgress:(id)sender;

-(IBAction) stopProgress:(id)sender;

@end

2 .m file

@implementationProgressViewViewController

@synthesizeprogressview;

@synthesizebarprogressview;

- (void)viewDidLoad

{

self.progressview=nil;

self.barprogressview=nil;

[superviewDidLoad];

// 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;

[superdealloc];

}

- (void)viewDidUnload

{

self.progressview=nil;

self.barprogressview=nil;

[superviewDidUnload];

// 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=[NSTimerscheduledTimerWithTimeInterval:0.03f

target:self

selector:@selector(timerChanged:)

userInfo:nil

repeats:YES];

//[timerretain];

startButton.enabled=NO;

stopButton.enabled=YES;

}

-(IBAction) stopProgress:(id)sender

{

[timerinvalidate];

//[timerrelease];

//timer=nil;

self.progressview.progress=0.0f;

self.barprogressview.progress=0.0f;

startButton.enabled=YES;

stopButton.enabled=NO;

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容