TinyVFL is a tiny library to replace the native virtual format language of Auto Layout. The native VFL is string-base and not user friendly in Swift. TingVFL implement with type safe method and easy to use.
Original Virtual Format Language code(Old way):
NSLayoutConstraint.constraints(withVisualFormat: "V:|-[view1][view2(90)]-(space@750)-[view3(==view1)]",
options: [.alignAllLeft, .alignAllRight],
metrics: ["space": NSNumber(value: spaceValue)],
views: ["view1": view1, "view2": view2, "view3": view3])
Virtual Format Language with TinyVFL:
VFL.v(.superView,
.space(),
.view(view1),
.view(view2, size: 90),
.space(spaceValue, priority: 750),
.view(view3, equal:view1))
.withOptions([.alignAllLeft, .alignAllRight])
.constraints
Even simplier:
VFL.v(.top,
.s(),
.v(view1),
.v(view2, 90),
.s(spaceValue, p: .defaultHigh),
.v(view3, e:view1))
.withOptions([.alignAllLeft, .alignAllRight])
.active()
- TinyVFL: A safer virtual format language for Auto Layout
- TinyVFL: 更安全的Auto Layout Virtual Format Language实现
More similar articles can found in TinySeries