Work in progress 🙄
Because you can write this:
let label = UILabel()
.text("My awesome title")
.textColor(.whiteColor())
.backgroundColor(.blackColor())
.textAlignment(.Center)
.font(.boldSystemFontOfSize(17))
.layerCornerRadius(2)
.clipsToBounds(true)
instead of this:
let label = UILabel()
label.text = "My awesome title"
label.textColor = .whiteColor()
label.backgroundColor = .blackColor()
label.textAlignment = .Center
label.font = .boldSystemFontOfSize(17)
label.layer.cornerRadius = 2
label.clipsToBounds = true
The awesome thing is, you can thin your viewDidLoad
or init
methods:
class MyIntroView: UIView {
let coverView = UIView().backgroundColor(.redColor())
let titleLabel = UILabel().font(.boldSystemFontOfSize(17))
let subTitleLabel = UILabel().font(.systemFontOfSize(12)).textColor(.grayColor())
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
}
}
To run the example project, clone the repo, and run pod install
from the Example directory first.
ChainableSwift is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "ChainableSwift"
Then run pod install
command.
Denis Sushko, [email protected]
ChainableSwift is available under the MIT license. See the LICENSE file for more info.