简体   繁体   中英

Autolayout of 2 multiline UILabels

I'm making an "Latest news" XIB that I will reuse through my storyboard.

The thing is that the XIB file is for some reason having a much greater height than it should. I have tried using preferredMaxLayoutWidth or setting the height constraint to be a >= x but nothing worked.

Here is my view hierarchy, and the constraints of the views: 在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

The result is this:

在此处输入图片说明

Here is the hierarchy of the storyboard scene: 在此处输入图片说明

I hope this is enough information, and thanks in advance!

My guess from looking at your nib layouts is that the top level Container is constrained to the top and bottom of it's super view. That constraint is probably beating out the other constraints. Break those constraints and see if that helps.

The problem was that the Content Hugging Priority and the Content Compression Resistance Priority weren't correctly set, so the UIImageView on the left was always expanding to its maximum height.

The problem was gone once the Content Priorities were set so the text on the right was determining the height of the container.

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