UIProgressView和UIActivityIndicator有些類似
但是不同之處在於,
UIProgressView能夠更加精確的反應進度
UIActivityIndicator則只能表示事物在進行中
有一個例子是在Mail程序中當在下載信息的時候,有一個UIProgressView顯示在底部
- (void)viewDidLoad
{
[super viewDidLoad];
//定義一個進度條
UIProgressView *progressV = [[UIProgressView alloc] init];
progressV.frame = CGRectMake(100, 100, 2, 300);
//進度值
progressV.progress = 0.1;
/*
typedef NS_ENUM(NSInteger, UIProgressViewStyle) {
UIProgressViewStyleDefault, // 默認狀態
UIProgressViewStyleBar, // 一般用於toolbar
};
*/
progressV.progressViewStyle = UIProgressViewStyleDefault;
// 設置填充部分的顏色(假設進度到30%, 那30%的顏色就是這個屬性)
progressV.progressTintColor = [UIColor greenColor];
// 設置未填充部分的顏色(假設進度到30%, 那70%的顏色就是這個屬性)
progressV.trackTintColor = [UIColor redColor];
// 設置填充部分的圖片 設置圖片後progressTintColor無效
progressV.progressImage = [UIImage imageNamed:@"1"];
// 設置未填充部分的圖片 設置圖片後trackTintColor無效
progressV.trackImage = [UIImage imageNamed:@"2"];
[self.view addSubview:progressV];
}
//關鍵progress屬性當前進度值,並且設置是否需要動畫
- (void)setProgress:(float)progress animated:(BOOL)animated
{
}