🔗
ChainableSwift
进行中
为什么?
因为您可以这样写:
let label = UILabel()
.text("My awesome title")
.textColor(.white)
.backgroundColor(.black)
.textAlignment(.center)
.font(.boldSystemFont(ofSize: 17))
.layerCornerRadius(2)
.clipsToBounds(true)
而不是这样写:
let label = UILabel()
label.text = "My awesome title"
label.textColor = .white
label.backgroundColor = .black
label.textAlignment = .center
label.font = .boldSystemFont(ofSize: 17)
label.layer.cornerRadius = 2
label.clipsToBounds = true
奇妙的是,您可以将 `viewDidLoad` 或 `init` 方法简化
class MyIntroView: UIView {
let coverView = UIView().backgroundColor(.red)
let titleLabel = UILabel().font(.boldSystemFont(ofSize: 17))
let subTitleLabel = UILabel().font(.systemFont(ofSize: 12)).textColor(.gray)
init() {
super.init(frame: CGRect.zero)
addSubview(coverView)
coverView.addSubview(titleLabel)
coverView.addSubview(subTitleLabel)
// ...
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func configure(title: String, subtitle: String?) {
titleLabel.text = title
subTitleLabel.text = subtitle
}
}
使用方法
要运行示例项目,请克隆仓库,然后首先从示例目录运行 `pod install
`。
安装
ChainableSwift 通过 CocoaPods 提供使用。要安装它,只需将以下行添加到您的 Podfile 中:
pod "ChainableSwift"
然后运行 `pod install
` 命令。
作者
Denis Sushko, [email protected]
许可证
ChainableSwift 使用 MIT 许可证。更多信息请参阅 LICENSE 文件。