Skip to content

bestwnh/TinyVFL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TingVFL logo 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.

Sample Code

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()

More detail can be found in these articles:

More similar articles can found in TinySeries