Xcode 4和界面生成器:编辑垂直间距约束(锚点顶部,而不是底部) [英] Xcode 4 and Interface Builder: Editing Vertical Spacing Constraint (Anchor Top, not Bottom)

查看:117
本文介绍了Xcode 4和界面生成器:编辑垂直间距约束(锚点顶部,而不是底部)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小部件在设备上未正确布局(在 在IB中,确定,但它不是很正确)。小部件是一个标签,它位于中间屏幕。 Interface Builder给它一个带有Bottom Anchor的垂直空间约束。这里,底部表示屏幕底部(而不是下面的小部件,或锚定到顶部屏幕)。



我在检查器,但我没有看到如何改变到顶部锚点(优选地,到上面的小部件)。我尝试阅读Apple的。


I've got a widget that is not laying out correctly on device (its looks OK in IB, but its not quite right). The widget is a label and its located about mid-screen. Interface Builder gave it a Vertical Space Constraint with a 'Bottom Anchor'. Here, bottom means bottom of the screen (rather than a widget below, or anchor to top screen).

I'm in the inspector, but I don't see how to change to a top anchor (preferably, to the widget above). I tried reading Apple's docs and Editing Constraints in particular, but it was a confusing and did not explain how to make the change (or I missed the discussion - which was 7 sentences).

Below is a screen capture under Interface Builder showing the Vertical Space Constraint anchored to the bottom of the screen. And its attributes leave a lot to be desired - Equal, Constant and Priority don't really help.

Does anyone know how to edit constraints? Specifically, I want to (1) change a vertical spacer's anchor from bottom to top; and (2) anchor against the widget above, and not the top of the screen.

解决方案

Select the "Embedded" and the "Calculated" element together by shift-clicking.

With those two elements selected, use the constraints menu:

This menu, together with careful selection of elements, is central to happy editing of constraints in IB. In your case, choose the central item, the Pin menu. Choose Vertical Spacing - this will create a new constraint on vertical spacing between your two elements. Alternatively, select a single element and pin "Top space to superview" to pin to the top instead of the bottom.

You can now select and delete the vertical spacing to the bottom of the view. IB wouldn't let you delete this before since you have to have a complete, non-ambiguous set of constraints. After adding your new vertical spacing constraint, you now have this.

To illustrate further, here is an empty view controller, with a single text field which I have dragged on:

All of the constraints are purple, which means IB has added them for me (they are System constraints) and they can't be removed - they are the minimum constraints needed to position and size the text field.

Now, I'll select the text field, and pin the top space to the superview:

Now you can see that the two vertical space constraints have changed to blue (they are now user constraints) and they have a thicker appearance in the editor. This means that one of them can be deleted. I select the constraint for the bottom space and hit delete:

Note that this still has the appearance of a user constraint - but if I try to delete it, IB will automatically recreate the system constraint pinning to the bottom of the superview, getting us back to square one.

I have written about this, and similar autolayout topics, here.

这篇关于Xcode 4和界面生成器:编辑垂直间距约束(锚点顶部,而不是底部)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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