This is a collection of helper functions to layout views in Swift.
- Set the width, height or size of a view
- Center a view horizontally or vertically in its superview
- Size a view to the width or height of its superview
- Size a view to fill its superview
Change the width or height of a view
view.layoutWidth(30.0)
view.layoutHeight(40.0)
Or change both width and height at once
view.layoutHeight(30.0)
Fill the view's width or height out to its superview
view.layoutFullWidth()
view.layoutFullHeight()
Add an optional margin to the leading / trailing or top / bottom edge of the view
layout.layoutFullWidth(10.0)
layout.layoutFullHeight(10.0)
Center a view in its superview horizontally or vertically
view.layoutCenterHorizontally()
view.layoutCenterVertically()
Or center it in both directions
view.layoutCenter()
If you want you can store the constraints that RSLayout creates in order to clear them or replace them later on.
let constraintGroup = view.layoutFullWidth()
view.clearConstraintGroup(constraintGroup)
view.layoutWidth(30.0)