简体   繁体   中英

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

I have 3 labels arranged like so:

在此处输入图片说明

I want to add a gap between the trailing edges of line 1 and 2 and the leading edge of the 3rd label. 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.

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. 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.

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?

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). 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.

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