Simplinit
Swift组件初始化的超级语法糖
1.安装
CocoaPods在这里插入代码片
- 在你的podfile中添加:
pod 'Simplinit'
- 然后在命令行窗口中运行
pod install
2.使用
-
只需要
import Simplinit
-
然后你就可以像这样初始化UIButton,其他的组件包括UILabel等也支持
var newBtn = UIButton() .size12 .weightMedium .titleColorTheme .bgColorBlue .hiTitleNomal(title: "open") .hiImgNormal(imgName: "openImg", position: .top)
-
相当于:
let btn = UIButton() btn.setTitle("open", for: .normal) btn.setImage(UIImage(named: "openImg"), for: .normal) btn.titleLabel?.font = UIFont.systemFont(ofSize: 12, weight: .medium) btn.backgroundColor = .blue btn.setTitleColor(.black, for: .normal)
让组件初始化更优雅~
3.作者
HisongMo(old: Thered-key)
4.从Github中打开
喜欢的给个星星吧~