简体   繁体   中英

IOs Autolayout top position

I've a problem with my layout and don't find suggestions to solve. My scenario is:

I've 2 views (a UIImageView and a UILabel) side by side and with dynamic height and I need to put another view bellow the tallest of the two views.

This image illustrates my problem, but I'm creating that views programmatically.

http://i.stack.imgur.com/fRSib.png

These are my constraints:

H:|-8-[UIImageView]-8-[Label1]-8|
V:|-8-[UIImageView]
V:|-8-[Label1]
H:|-8-[Label2]-8|
V:[UIImageView]-(>=8)-[Label2]
V:[Label1]-(>=8)-[Label2]

I know that my layout is ambiguous, but I can't to solve this.

Thanks for help

You need to add constraints with priorities and you need an additional constraint. Your current spec is ambiguous because there are multiple potential solutions.

The 2 constraints to position the Label2 based on the heights need to be high priority (the default). You also need another constraint of a low priority which tells the layout system what you prefer - Ie That the y position should be the maximum, because the low priority constraint specifies that the label should be pinned to the bottom of the container / a static value larger then the possible heights of the other views.

The visual constraint language is a convenience but it doesn't allow you to specify everything.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM