✨ Super sweet syntactic sugar for Constraints in UIKit.
✨ A Swift Autolayout DSL for iOS
//In your controller
let myView = View()
view.addSubview(myView)
myView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
myView.topAnchor.constraint(equalTo: self.view.topAnchor),
myView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
myView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor),
myView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor)
])
}
view.addSubview(myView)
myView.cBuild(make: .fillSuperview)
-
You can use
closure
to construct the constraint to your view.label.cBuilder { $0.leading.equal(to: leadingAnchor, offsetBy: 20) $0.top.equal(to: topAnchor, offsetBy: 10) }
-
Want to set your constraints with your own types? Just make that
label.cBuild(top: topAnchor, bottom: bottomAnchor, left: leadingAnchor, right: trailingAnchor)
-
A lot times you have set the view in center to super view, so...
label.cBuild(make: .centerInSuperView)
Clone project
- Open your Xcode, select a simulator, click the play button or
cmd + R
- Test in your cases, and don't worry to use
TranslateAutoRezingsMas.............................
CBuilder is under MIT license. See the LICENSE file for more info.