iOS: How to Align The Center of a View With The Bottom of Another View With AutoLayout

前端 未结 6 664
离开以前
离开以前 2021-02-02 15:52

I want to make the center of the head imageView with the bottom of the blue title imageView\'s keep alignment.

How can I do it by using Autolayout?

screen 4.0inc

6条回答
  •  说谎
    说谎 (楼主)
    2021-02-02 16:42

    This may help you. Totally based on AutoLayout, no extra view needed.

    • First set some constraints on the height and width and the location of the Cover image. (blue one)

    It is 0.4 of total height, equal width of the width, you can see its constrains.

    • Then I fix the height and width of the Avatar (green) image, make it horizontally center in width.

    Then choose both the cover image and avatar image, make them Align bottom edge.

    Now it turns this.

    • Last step, choose the 'Align Bottom to Cover Image', and make the constant to be half of the Avatar image's height. Done!

    This is the simplest way I've found now.

提交回复
热议问题