TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Dec 2017 |
SPMSupports SPM | ✗ |
Maintained by xiaoyaogaojian.
A simple syntax sugar for UIKit.
To run the example project, clone the repo, and run pod install
from the Example directory first.
swift
4.x
Chainable is available through CocoaPods. To install
it, simply add the following line to your Podfile:
pod 'Chainable'
Vanilla
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)
])
With 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)
]
}
You can also use SnapKit to make constraints, just replace layout
with snp_layout
.
.snp_layout {
$.center.equalToSuperview()
}
Vanilla
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)
With 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 is available under the MIT license. See the LICENSE file for more info.