FreshLayout SPM
-
Features.
- Property Wrapper
- Result Builder
- Overloading operator
- DSL/Snapkit syntax
- Write Unit Test
-
Set Constraints: you can use different method to set constraints to a view.
-
Set Constraints with:
- makeContraints
- remakeContraints
- updateContraints
Set constraints for a view that haven't constraints:
titleLabel.fresh.makeContraints { make in make.anchorTo(boundsOf: view) }
Delete all old constraints and set new constraints:
titleLabel.fresh.remakeContraints { make in make.anchorTo(boundsOf: view) }
Update old constraints and set new constraints:
titleLabel.fresh.updateContraints { make in make.anchorTo(boundsOf: view) }
-
-
Creation syntax: you can use different method to create constraints to a view.
-
Create constraint with .constraint():
- default
- constant
- multiplier
titleLabel.fresh.makeContraints { make in make.top.constraint(backgroundView.fresh.top, relation: equal) make.bottom.constraint(backgroundView.fresh.bottom.constant(20.0), relation: equal) make.left.constraint(backgroundView.fresh.bottom.multiplier(0.8), relation: equal) make.height.constraint(200, relation: equal) }
-
-
Creation syntax: you can use different method to easy set more constraints with only 1 declaration.
-
Create constraint with:
- anchorTo
- centerTo
titleLabel.fresh.makeContraints { make in make.anchorTo(boundsOf: view) }
titleLabel.fresh.makeContraints { make in make.centerTo(boundsOf: view) }
-
-
Overloading operator: for improve your code speed.
-
Create constraint with .constraint():
- == equal to
- <= less to
- >= great to
- + add constant
- * add multiplier
titleLabel.fresh.makeContraints { make in make.top <= backgroundView.fresh.top + 10.0 make.height == 100 }
-
You can use updateContraints for UIView.animate():
titleLabel.fresh.updateContraints { make in
make.anchorTo(boundsOf: view)
}
remember to use view.layoutIfNeeded() inside the block.