您的位置:首页 > 产品设计 > UI/UE

iOS——UIProgressView

2017-04-03 20:23 363 查看

一、概述

1. UIProgressView 是一个简单的进度条控件,用法较简单,属性也较少
2. 从名称就可以看出,它是一个视图并且直接继承 UIView,所以它不能相应一系列的事件,只是一个单纯显示的视图

二、属性

1. UIProgressView 对象重写了自己的 initWithFrame: 方法,目的是只能改变 width、height 不能改变

 - (instancetype)initWithFrame:(CGRect)frame;

2. 设置 UIProgressView 对象的风格

- (instancetype)initWithProgressViewStyle:(UIProgressViewStyle)style;

typedef NS_ENUM(NSInteger, UIProgressViewStyle) {
UIProgressViewStyleDefault, // 普通样式
UIProgressViewStyleBar // 工具栏样式
};

3. 设置 UIProgressView 对象的风格;默认为 UIProgressViewStyleDefault

@property(nonatomic)
UIProgressViewStyle progressViewStyle;

4. 设置进度条的当前值;默认为 0,并且范围在 0 ~ 1 之间

@property(nonatomic)
float progress; 

5. 设置已经走过进度条的颜色

@property(nonatomic,
strong, nullable)
UIColor* progressTintColor;

6. 设置还未走过进度条的颜色

@property(nonatomic,
strong, nullable)
UIColor* trackTintColor;

7. 设置已经走过进度条的图片

@property(nonatomic,
strong, nullable)
UIImage* progressImage;

8. 设置还未走过进度条的图片

@property(nonatomic,
strong, nullable)
UIImage* trackImage;

9. 设置进度条的当前置,并设置动画效果

- (void)setProgress:(float)progress animated:(BOOL)animated;

三、其他

1. 当要设置 UISlider 和 UIProgressView 关联时,有两种情况
1)UISlider 对象的 minimumValue 和 maximumValue 在 0 ~ 1 之间时(和 UIProgressView 的范围一致)
_progressView.progress = _slider.value;


2)UISlider 对象的 minimumValue 和 maximumValue 不在 0 ~ 1 之间时(和 UIProgressView 的范围不一致),此时需要将 UISlider 的值做一个百分比的转换
_progressView.progress = (_slider.value - _slider.minimumValue) / (_slider.maximumValue - _slider.minimumValue);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios UIProgressView