TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Sep 2015 |
SPMSupports SPM | ✗ |
Maintained by MATSUMOTO Yuji.
yavfl is Yet Anoter Visual Format Language for Auto Layout.
In yavfl, you can write the code of visual format language as follows:
visualFormat(label, textField) { l, t in
.V ~ |-40-[l,==32]
.V ~ |-40-[t,==32]
.H ~ |-20-[l,==t]-10-[t]-|
}
The equivallent code of the original visual format is follows:
let dic = ["l": label, "t": textField]
label.setTranslatesAutoresizingMaskIntoConstraints(false)
textField.setTranslatesAutoresizingMaskIntoConstraints(false)
let c1 = NSLayoutConstraint.constraintsWithVisualFormat("V:|-40-[l(32)]", options: nil, metrics: nil, views: dic)
let c2 = NSLayoutConstraint.constraintsWithVisualFormat("V:|-40-[t(32)]", options: nil, metrics: nil, views: dic)
let c3 = NSLayoutConstraint.constraintsWithVisualFormat("|-20-[l(==t)]-10-[t]-|", options: nil, metrics: nil, views: dic)
self.view.addConstraints(c1)
self.view.addConstraints(c2)
self.view.addConstraints(c3)
yavfl | origial |
---|---|
.H ~ [button]-[textField] |
[button]-[textField] |
.H ~ [button,>=50] |
[button(>=50)] |
.H ~ |-50-[purpleBox]-50-| |
|-50-[purpleBox]-50-| |
.V ~ [topField]-10-[bottomField] |
V:[topField]-10-[bottomField] |
.H ~ [maroonView]-0-[blueView] |
[maroonView][blueView] |
.H ~ [button,==100~20] |
[button(100@20)] |
.H ~ [button1,==button2] |
[button1(==button2)] |
.H ~ [flexibleButton,>=70,<=100] |
[flexibleButton(>=70,<=100)] |
.H ~ |-[find]-[findNext]-[findField,>=20]-| |
|-[find]-[findNext]-[findField(>=20)]-| |
visualFormat
supports up to 5 views.Some parts of the syntax are changed due to Swift's syntax limitation.
()
for view's predicate.
[button1,==button2]
instead of [button1(==button2)]
.~
instead of :
for orientation and @
for priority, because these can not be used for custom operators.
.H ~ |-[view]-|
instead of H:|-[view]-|
.[view,==100~200]
instead of [view(==100@200)]
..H
or .V
) and operator ~
are required for applying layout constraints.
~
is a trigger for creating and applying constraints.-
) is required between views.
[v1][v2]
is not allowed due to the syntax limitation. Use [v1]-0-[v2]
instead.==
, <=
or >=
) is required for predicate.
[view,100]
is not allowed. Use [view,==100]
instead.pod 'yavfl'
Or, just copy yavfl.swift
into your project.