[IOS]今天开始学UI---UIProgressView

本文介绍了iOS中UIProgressView组件,用于显示进度条,提高用户体验。UIProgressView有两种样式:Default和Bar,其中Default样式不透明,Bar样式未完成部分透明。主要属性包括:progress(0-1之间),progressTintColor,trackTintColor,progressImage和trackImage,可用于自定义进度条。通过代码示例展示了如何更新progress属性以模拟进度变化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

UIProgressView 作用:显示当前进度 以进度条的形式 提高用户体验

UIProgressView 有两种样式:1.UIProgressViewStyleDefault 2.UIProgressViewStyleBar


两者的区别在于进度条样式UIProgressViewStyleBar 右边为透明 即未完成部分为透明

而默认的为不透明

(上:Default,下:Bar)


ProgressView主要可以设置的属性

progress:float 类型 0 - 1 改变值可以达到改变进度显示的作用

progressTintColor

trackTintColor

progressImage

trackImage

以上四种是用来定制进度条的

下面图解上述四属性




该View使用起来也是比较容易的

直接上代码 演示效果  添加了一个定时更新progress属性的定时器 模拟进度

#import "ViewController.h"
const NSUInteger kProgressViewControllerMaxProgress = 100;
@interface ViewController ()
@property (nonatomic,strong) UIProgressView *view1;
@property (nonatomic,strong) UIProgressView *view2;
@property (nonatomic,strong) UIProgressView *view3;
@property (nonatomic,assign) int currentProgress;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor clearColor];
    _view1 = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
    _view2 = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
    _view3 = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];

    CGPoint center = self.view.center;
    _view1.frame = CGRectMake(0, 0, 200, 50);
    _view2.frame = CGRectMake(0, 0, 200, 50);
    _view3.frame = CGRectMake(0, 0, 200, 50);

    _view1.center = CGPointMake(center.x, center.y-100);
    _view2.center = CGPointMake(center.x, center.y+100);
    _view3.center = CGPointMake(center.x, center.y);

    [self.view addSubview:_view1];
    [self.view addSubview:_view2];
    [self.view addSubview:_view3];

    [_view3 setTintColor:[UIColor redColor]];
    [_view3 setTrackTintColor:[UIColor greenColor]];
    _currentProgress = 0;
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.03f target:self selector:@selector(simulateProgress:) userInfo:nil repeats:YES];




}



- (void)simulateProgress:(NSTimer *)timer{
    _currentProgress++;
    if (_currentProgress>=100) {
        [timer invalidate];
    }
    [_view1 setProgress:(double)_currentProgress/kProgressViewControllerMaxProgress];
    [_view2 setProgress:(double)_currentProgress/kProgressViewControllerMaxProgress];
    [_view3 setProgress:(double)_currentProgress/kProgressViewControllerMaxProgress];
}






that's all

thx


Everything you see on Screen is UIView.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值