测试已测试 | ✗ |
Lang语言 | SwiftSwift |
许可证 | MIT |
发布最新版本 | 2017年12月 |
SPM支持 Swift Package Manager (SPM) | ✗ |
由 xiaoyaogaojian 维护。
UIKit 的简单语法糖。
要运行示例项目,请克隆仓库,并首先在 Example 目录下运行 pod install
。
swift
4.x
Chainable 通过 CocoaPods 提供。要安装
它,只需将以下行添加到您的 Podfile
pod 'Chainable'
普通
let label = UILabel()
label.text = "😂"
label.textColor = .red
view.addSubview(label)
NSLayoutConstraint.activate([
label.centerXAnchor.constraint(equalTo: view.centerXAnchor),
label.centerYAnchor.constraint(equalTo: view.centerYAnchor)
])
使用 Chainable
UILabel().chain
.config {
$0.text = "😄"
$0.textColor = .green
}
.add(toSuperView: view)
.layout {
[
$0.centerXAnchor.constraint(equalTo: view.centerXAnchor),
$0.centerYAnchor.constraint(equalTo: view.centerYAnchor)
]
}
您也可以使用 SnapKit 来设置约束,只需将 layout
替换为 snp_layout
即可。
.snp_layout {
$.center.equalToSuperview()
}
普通
let alertController = UIAlertController(title: "Title", message: "Some message", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel))
alertController.addAction(UIAlertAction(title: "OK", style: .default) { _ in
print("OK")
})
present(alertController, animated: true)
使用 Chainable
UIAlertController(title: "Title", message: "Some message", preferredStyle: .alert).chain
.config {
$0.addAction(UIAlertAction(title: "Cancel", style: .cancel))
$0.addAction(UIAlertAction(title: "OK", style: .default) { _ in
print("OK")
})
}
.presented(by: self)
xiaoyaogaojian, [email protected]
Chainable 在 MIT 许可证下提供。有关更多信息,请参阅 LICENSE 文件。