This pod
contains a collection of Swift extensions that reduce boilerplate code in new iOS projects
Add the following line to your Podfile
:
pod 'WybroStarter'
We have added new functionality to UIView
, NSLayoutConstraint
and UIColor
to make it easier to build projects without xib
files
Specify that a view will be using constraints. A good time to do this is while the view is being added as a subview:
view.addSubview(yourView.usingConstraints())
Center a view horizontally or vertically within another view:
let horizontal = yourView.center(in: view, type: .horizontal)
let vertical = yourView.center(in: view, type: .vertical)
Create constraints for multiple views and formats with VFL:
let constraints = NSLayoutConstraint.constraints(
formats: ["V:|[view]|",
"H:|[view]|"],
views: ["view": yourView]
)
A nice pattern to follow involves creating a function to return the constraints you want and chaining an activate
to enable all of the constraints:
func layoutConstraints() -> [NSLayoutConstraint] {
// create constraints here
return constraints
}
layoutConstraints().activate()
Create an instance of UIColor
using a hex
string:
let color = UIColor(hex: "FFFFFF")