简体   繁体   English

如何在彼此不相邻的两个元素之间添加拖尾/前导约束

[英]How to add tailing/leading constraint between two elements which aren't next to each other

I have 3 labels arranged like so: 我有3个标签排列如下:

在此处输入图片说明

I want to add a gap between the trailing edges of line 1 and 2 and the leading edge of the 3rd label. 我想在第1行和第2行的后沿与第3个标签的前沿之间添加一个间隙。 If the 3rd label is on the same vertical position of one of these then this is straightforward as XCode will display line 1 (or line 2) in the add new constraint pop-up. 如果第3个标签位于其中之一的相同垂直位置,则这很简单,因为XCode将在添加新约束弹出窗口中显示第1行(或第2行)。

But when the 3rd label is not on the same vertical plane as either of these labels then XCode is not presenting either Label 1 or Label 2 as an option to add a gap between. 但是,当第三个标签与两个标签都不在同一垂直平面上时,则XCode不会显示“标签1”或“标签2”作为在两者之间添加间隙的选项。 ie if I select the 3rd label and bring up the pop up: 即,如果我选择第三个标签并弹出弹出窗口:

在此处输入图片说明

Similarly if I try to add the constraint from Label 1 or Label 2 - the 3rd label not not appear as an option. 同样,如果我尝试从标签1或标签2添加约束,则第3个标签不会作为选项出现。

So how can I add constraints such that line 1 and line 2 do not overlap the start of the 3rd label without adding a hardcoded value for the width of these? 那么,如何在不为这些宽度添加硬编码值的情况下添加约束,使第1行和第2行不与第3个标签的开头重叠?

Control-drag from one label to the other and add a “Horizontal Spacing” constraint (or “Leading Space” or “Trailing Space”; any horizontal constraint between the two views will do). 按住Control键从一个标签拖动到另一个标签,然后添加“水平间距”约束(或“前导空间”或“尾随空间”;两个视图之间的任何水平约束都可以)。 Then select the new constraint (eg by clicking it in the document outline). 然后选择新的约束(例如,通过在文档大纲中单击它)。 You can edit it in the Attributes inspector to set one end to one label's trailing edge and the other end to the other label's leading edge, and you can set the constant to the size of your intended gap. 您可以在“属性”检查器中对其进行编辑,以将一端设置为一个标签的后沿,另一端设置为另一标签的前边缘,并且可以将常数设置为预期间隙的大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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