iOS——UIProgressView在工程中的簡單應(yīng)用

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),我就是那只傻子纵刘!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末邀窃,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子假哎,更是在濱河造成了極大的恐慌瞬捕,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,386評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件位谋,死亡現(xiàn)場離奇詭異山析,居然都是意外死亡,警方通過查閱死者的電腦和手機掏父,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,142評論 3 394
  • 文/潘曉璐 我一進店門笋轨,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事爵政〗龇恚” “怎么了?”我有些...
    開封第一講書人閱讀 164,704評論 0 353
  • 文/不壞的土叔 我叫張陵钾挟,是天一觀的道長洁灵。 經(jīng)常有香客問我,道長掺出,這世上最難降的妖魔是什么徽千? 我笑而不...
    開封第一講書人閱讀 58,702評論 1 294
  • 正文 為了忘掉前任,我火速辦了婚禮汤锨,結(jié)果婚禮上双抽,老公的妹妹穿的比我還像新娘。我一直安慰自己闲礼,他們只是感情好牍汹,可當(dāng)我...
    茶點故事閱讀 67,716評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著柬泽,像睡著了一般慎菲。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上锨并,一...
    開封第一講書人閱讀 51,573評論 1 305
  • 那天露该,我揣著相機與錄音,去河邊找鬼琳疏。 笑死有决,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的空盼。 我是一名探鬼主播书幕,決...
    沈念sama閱讀 40,314評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼揽趾!你這毒婦竟也來了台汇?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,230評論 0 276
  • 序言:老撾萬榮一對情侶失蹤篱瞎,失蹤者是張志新(化名)和其女友劉穎苟呐,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體俐筋,經(jīng)...
    沈念sama閱讀 45,680評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡牵素,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,873評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了澄者。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片笆呆。...
    茶點故事閱讀 39,991評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡请琳,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出赠幕,到底是詐尸還是另有隱情俄精,我是刑警寧澤,帶...
    沈念sama閱讀 35,706評論 5 346
  • 正文 年R本政府宣布榕堰,位于F島的核電站竖慧,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏逆屡。R本人自食惡果不足惜圾旨,卻給世界環(huán)境...
    茶點故事閱讀 41,329評論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望康二。 院中可真熱鬧碳胳,春花似錦、人聲如沸沫勿。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,910評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽产雹。三九已至,卻和暖如春翁锡,著一層夾襖步出監(jiān)牢的瞬間蔓挖,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,038評論 1 270
  • 我被黑心中介騙來泰國打工馆衔, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留瘟判,地道東北人。 一個月前我還...
    沈念sama閱讀 48,158評論 3 370
  • 正文 我出身青樓角溃,卻偏偏與公主長得像拷获,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子减细,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,941評論 2 355

推薦閱讀更多精彩內(nèi)容

  • 繼“明日之子”之后匆瓜,昨晚“薛之謙”三個字再一次刷遍全網(wǎng)。 薛之謙與前妻復(fù)婚了未蝌,這個不正經(jīng)的男人將余生所有的深情再一...
    暴走蘿莉Lee閱讀 1,286評論 0 1
  • “ 你幫助了迷路的我 如果能實現(xiàn) 我想帶你去看絢爛的山嵐 去看秀麗的溪谷 這份心情 人類是如何稱呼的呢 “ 我們大...
    六月LIa閱讀 202評論 0 0
  • 晚上少熬夜驮吱,不要來回刷手機了,越刷越孤獨萧吠。 胃不好就少吃辣椒冷飲過熱食物左冬, 容易發(fā)胖的體質(zhì)管不住嘴就多運動。 一個...
    動感光波嗶嗶嗶閱讀 177評論 0 0
  • 第十二期《HIFI人物》企業(yè)篇之香港東騰音響:聽聽自己動手的聲音 英國君子纸型, 看到這個產(chǎn)品后拇砰,且不論是否對其熟悉九昧。...
    HiFi996閱讀 552評論 0 50