iOS UIActivityIndicatorView和UIProgressView控件

UIActivityIndicatorViewUIProgressView控件用来显示进度。

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

显示如下
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值