Search code examples
swiftautolayoutconstraintsios-autolayoutvisual-format-language

Visual Format Language Multiple Predicates


I am working with Visual Format Language and I run in to an issue.

Take for example the Multiple Predicates example of Apple:

Apple Layout Guide

Multiple Predicates

[flexibleButton(>=70,<=100)]

If I want the size of the button at its normal state to be 100 and if that does not work the button can decrease till 70. How can I achieve this?

My example looks like this:

"H:|-(>=10)-[Textfield]-(>=5,<=50)-[firstButton]-(<=50)-[secondButton]-(>=10)-|"

So I want to have a standard margin of 50 but if that does not work the Textfield is allowed to expand till 5 but not any further. What is the usual way to make that happen? Because right now it just chooses the "5"-Constraint and stays there.


Solution

  • I used priorities, now it does work. This is my solution:

    Visual language:

    "H:|-(>=10)-[Textfield]-(50@800,>=5@790)-[firstButton]-(<=50)-[secondButton]-(>=10)-|"

    On top of that I had to set the priority of the compression resistance.

    Textfield.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 750), for: .horizontal)