使用自动布局,如何在同一“线”上制作两个标签。它们的宽度是动态的(根据每个人需要的宽度进行调整)? [英] Using Auto Layout, how do I make two labels on the same "line" be dynamic in their widths (adjusting with how wide each one needs to be)?

查看:68
本文介绍了使用自动布局,如何在同一“线”上制作两个标签。它们的宽度是动态的(根据每个人需要的宽度进行调整)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有两个UILabel,一个是URL,一个是计时器:

Say I have two UILabels, one is a URL and one is a timer:

[http://website.com/link/to/specific/story] [9m 42s]

但是计时器UILabel更改宽度很多。有时它只是 12s ,有时它是 125h 32m 8s 。有很多变化。我希望计时器UILabel占用所需的宽度,而的URL标签占用其余的。这意味着如果计时器更长,更短的网址等。

But the "timer" UILabel changes width a lot. Sometimes it is just 12s for example, other times it is 125h 32m 8s. There's a lot of variability. I want the timer UILabel to take up as much width as it needs and the URL label to take up the rest. This means if the timer is longer, shorter URLs, etc.

如何在自动布局中执行此操作?最好在Interface Builder中?

How do I do this in Auto Layout? Preferably in Interface Builder?

推荐答案

你应该设置压缩阻力,URL标签必须具有较低的值;

You should set the compression resistance, URL label must have lower value;

将标签之间的水平空间设置为常量(例如零或默认值);

Set the horizontal space between labels to constant (for example zero or default);

设置每个标签的宽度并选择小于或更大的关系,这些值设定了缩小/扩大视图的限制。

Set width for each label and select "less than" or "greater that" relation, these values set limits for shrinking/expanding of the view.

这篇关于使用自动布局,如何在同一“线”上制作两个标签。它们的宽度是动态的(根据每个人需要的宽度进行调整)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆