UIProgressView顧名思義用來顯示進度的,如音樂巡雨,視頻的播放進度,和文件的上傳下載進度等婉支。UIProgressView也是常用的控件鸯隅。本文只介紹最簡單的布局使用澜建。
<pre>
初始化方法
-(instancetype)initWithFrame:(CGRect)frame ;
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder ;
- (instancetype)initWithProgressViewStyle:(UIProgressViewStyle)style; 這個最常用
@property(nonatomic) UIProgressViewStyle progressViewStyle;
@property(nonatomic) float progress;
進度條顏色
@property(nonatomic, strong, nullable) UIColor* progressTintColor;
設(shè)置背景顏色
@property(nonatomic, strong, nullable) UIColor* trackTintColor;
設(shè)置進度條
@property(nonatomic, strong, nullable) UIImage* progressImage;
設(shè)置背景圖片
@property(nonatomic, strong, nullable) UIImage* trackImage;
是否使用動畫更改進度條的值
— (void)setProgress:(float)progress animated:(BOOL)animated);
@property(nonatomic, strong, nullable) NSProgress *observedProgress;
</pre>
本Demo并沒有使用navigationBar所以向挖,全部使用了自定義View。界面拆分如下
一炕舵、今天的主角:UIProgressView
我們可以從圖中看中何之,這個頁面中需要使用3個一樣progressView。所以我們將這個可以抽取成ProgressView類咽筋。
ProgressView類需求:
1.1 具有兩個Lable溶推,一個ProgressView
1.2 需要對外提供賦值的方法。
直接上代碼
ProgressView.h
#import <UIKit/UIKit.h>
#import "Masonry.h"
@interface ProgressView : UIView
@property (nonatomic, strong) UILabel * progressTitleLabel;
@property (nonatomic, strong) UILabel * progressAccountLabel;
@property (nonatomic, strong) UIProgressView * rateProgressView;
+ (ProgressView *)progressTitle:(NSString *)title progressAccount:(int)account rateProgress:(CGFloat)rate rateProgressColor:(UIColor *)progressColor;
@end
ProgressView.m
#import "ProgressView.h"
@implementation ProgressView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self p_setupViews];
}
return self;
}
- (void)p_setupViews
{
self.progressTitleLabel = [[UILabel alloc] init];
self.progressTitleLabel.textAlignment = NSTextAlignmentLeft;
self.progressTitleLabel.textColor = [UIColor colorWithRed:166/255.0 green:166/255.0 blue:166/255.0 alpha:1];
[self addSubview:self.progressTitleLabel];
self.progressAccountLabel = [[UILabel alloc] init];
self.progressAccountLabel.textColor = [UIColor colorWithRed:166/255.0 green:166/255.0 blue:166/255.0 alpha:1];
self.progressAccountLabel.textAlignment = NSTextAlignmentRight;
[self addSubview:self.progressAccountLabel];
// 進度條初始化
self.rateProgressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
// 進度條的底色
self.rateProgressView.trackTintColor = [UIColor colorWithRed:199/255.0 green:198/255.0 blue:198/255.0 alpha:1];
self.rateProgressView.layer.masksToBounds = YES;
self.rateProgressView.layer.cornerRadius = 1;
[self addSubview:self.rateProgressView];
}
- (void)layoutSubviews
{
[super layoutSubviews];
[self.progressTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.equalTo(self);
make.width.mas_equalTo(200);
make.height.mas_equalTo(30);
}];
[self.progressAccountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.right.equalTo(self);
make.width.mas_equalTo(100);
make.height.mas_equalTo(30);
}];
[self.rateProgressView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(self);
make.top.equalTo(self.progressTitleLabel.mas_bottom).offset(5);
make.height.mas_equalTo(5);
}];
}
+ (ProgressView *)progressTitle:(NSString *)title progressAccount:(int)account rateProgress:(CGFloat)rate rateProgressColor:(UIColor *)progressColor
{
ProgressView * progressView = [[ProgressView alloc] init];
progressView.progressTitleLabel.text = title;
progressView.progressAccountLabel.text = [NSString stringWithFormat:@"%d",account];
// 進度條的進度
progressView.rateProgressView.progress = rate;
// 進度條的顏色
progressView.rateProgressView.progressTintColor = progressColor;
return progressView;
}
具體使用
github地址:https://github.com/zhangyanxiao/IDCameraDemo----demo
在這個末尾紀(jì)念一下奸攻,一只傻子蒜危!
在之前使用簡書、貼代碼的時候睹耐,好像是7個月還是10個月里辐赞,一直在每行代碼前tab+tab,按了不知道多少的tab和復(fù)制粘貼。剛剛硝训,用來一下"pre",好嘛响委!??!知識就是力量窖梁。
好吧赘风,我承認(rèn),我就是那只傻子纵刘!