简体   繁体   中英

Autolayout, flexible container - container's intrinsic content size

I want to design a reusable flexible component in interface builder, consisting of title and subtitle (for simplicity of this question).

Both labels have 8 pt left and right constraints, 8 pt top constraint (title), 8 pt vertical spacing between them, and 8 pt bottom constraint (subtitle).

Because labels have horizontal constraints, and zero as number of lines, what I assume is they will nicely expand vertically if more text is applied, and because of vertical spacing they will never overlap.

Unfortunately I receive a content priority ambiguity, perhaps because the container height is already defined in storyboard - 66 (21 * two labels + 8 * 3 constraints).

What I want to achieve is that later if provided text or font settings need more space the container itself grows. So the height of the container shouldn't be hardcoded to 66, but dynamic, I have no idea how to set it up in interface builder. I probably know how to do it in code, but prefer IB.

Attaching some screenshots:

界面生成器1

[ 界面生成器2

Actually, you can set the label's height with constraint, then change the constraint to ">=" replace the "=".

在此处输入图片说明

It works well, and the height is the minimum height of label.

在此处输入图片说明

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