UIActivityIndicatorView
和UIProgressView
控件用来显示进度。
1. UIActivityIndicatorView控件
// 风格类型
@property(nonatomic) UIActivityIndicatorViewStyle activityIndicatorViewStyle;
// 停止转动时是否隐藏,默认是YES
@property(nonatomic) BOOL hidesWhenStopped;
// 转动图形的颜色
@property (null_resettable, readwrite, nonatomic, strong) UIColor *color;
UIActivityIndicatorView
默认是不转动的,startAnimating
开始转动,stopAnimating
停止转动。
示例代码
UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc]
initWithFrame:CGRectMake(100, 100, 50, 50)];
activityIndicatorView.hidesWhenStopped = NO;
[self.view addSubview: activityIndicatorView];
[activityIndicatorView startAnimating];
UIActivityIndicatorView *largeActivityIndicatorView = [[UIActivityIndicatorView alloc]
initWithFrame:CGRectMake(220, 100, 50, 50)];
largeActivityIndicatorView.color = [UIColor magentaColor];
if (@available(iOS 13.0, *)) {
largeActivityIndicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleLarge;
}
[self.view addSubview: largeActivityIndicatorView];
[largeActivityIndicatorView startAnimating];
dispatch_time_t stopTime = dispatch_time(DISPATCH_TIME_NOW, 3 * NSEC_PER_SEC);
dispatch_after(stopTime, dispatch_get_main_queue(), ^(void){
[activityIndicatorView stopAnimating];
[largeActivityIndicatorView stopAnimating];
});
显示如下
2. UIProgressView控件
// 进度条类型
@property(nonatomic) UIProgressViewStyle progressViewStyle;
// 进度条的进度值,0.0~1.0,默认值为0.0
@property(nonatomic) float progress;
// 进度值左边的颜色
@property(nonatomic, strong, nullable) UIColor* progressTintColor;
// 进度值右边的颜色
@property(nonatomic, strong, nullable) UIColor* trackTintColor;
// 进度值左边的图片
@property(nonatomic, strong, nullable) UIImage* progressImage;
// 进度值右边的图片
@property(nonatomic, strong, nullable) UIImage* trackImage;
示例代码
UIProgressView *progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(50, 100, 200, 50)];
progressView.progress = 0.3;
[self.view addSubview: progressView];
UIProgressView *barProgressView = [[UIProgressView alloc] initWithFrame:CGRectMake(50, 150, 200, 50)];
barProgressView.progress = 0.3;
barProgressView.progressViewStyle = UIProgressViewStyleBar;
barProgressView.progressTintColor = [UIColor greenColor];
barProgressView.trackTintColor = [UIColor redColor];
[self.view addSubview: barProgressView];
显示如下