Centering a view in its superview using Visual Format Language

前端 未结 14 1342
天命终不由人
天命终不由人 2020-12-02 03:52

I just started learning AutoLayout for iOS and had a look at Visual Format Language.

It all works fine except for one thing: I just can\'t get a view to center withi

14条回答
  •  一整个雨季
    2020-12-02 04:45

    Thanks to the answer from @Evgenii, I create a full example in gist:

    center the red square vertically with custom height

    https://gist.github.com/yallenh/9fc2104b719742ae51384ed95dcaf626

    You can center a view vertically by useing either VFL (which is not quite intuitive) or use constraints manually. By the way, I cannot combine both centerY and height together in VFL like:

    "H:[subView]-(<=1)-[followIcon(==customHeight)]"
    

    In the current solution VFL constraints are added separately.

提交回复
热议问题