通過(guò)這種方式、可以快速完成簡(jiǎn)單基礎(chǔ)UI的創(chuàng)建。
也不用在定義一堆的控件屬性、保持代碼干凈。
先看示例圖
1、簡(jiǎn)潔版


2、復(fù)雜版


省了代碼、看這舒心。
具體實(shí)現(xiàn)
核心:通過(guò)UIView的擴(kuò)展方式,分別對(duì)UIImageView、UILabel等常用控件挨個(gè)實(shí)現(xiàn)需要的方法和屬性。
噗、代碼格式?jīng)]弄出來(lái)、湊合著看吧!
統(tǒng)一創(chuàng)建:
///添加內(nèi)容
//格式1字符串、q_*n+數(shù)量/q_view_*h/q_*kf
//格式2數(shù)組、[格式1]
-(void)q_addSubitems:(id)item;
對(duì)應(yīng)獲取控件的:
/// 根據(jù)名字獲取元素
/// @paramname通過(guò) 數(shù)組 q_*k+下標(biāo)生成 單個(gè)直接用q_view_*h/或者
-(UIView*)q_subkey:(NSString*)name;
對(duì)應(yīng)具體屬性需要區(qū)別對(duì)待、(例如UIView+Label):
///文字
@property(nonatomic)NSString * ql_text;
///行數(shù)
@property(nonatomic)int ql_line;
///對(duì)齊
@property(nonatomic)NSTextAlignment ql_alignment;
///顏色
@property(nonatomic)UIColor * ql_color;
///字體
@property(nonatomic)UIFont * ql_font;
///富文本
@property(nonatomic)NSAttributedString * ql_att;
例如:UIView+Image
///獲取圖片
@property(nonatomic,readonly)UIImage * qi_img;
///設(shè)置圖片
@property(nonatomic)NSString * qi_icon;
///填充方式
@property(nonatomic)UIViewContentMode qi_mode;
結(jié)語(yǔ):
常用的控件就這四個(gè)、其他的也可擴(kuò)展、按照基本規(guī)則來(lái)就行、(先定義Key、然后在具體實(shí)現(xiàn))。
代碼地址
https://github.com/quua/QUIExt
最后祝你身份健康、再見。