简体   繁体   English

Xcode 6 Storyboard无法居中

[英]Xcode 6 Storyboard can't center

I have an issue trying to center an object in a storyboard. 我试图将一个对象放在故事板中。 I've created a new "Single-view Application" project, entered a main.Storyboard and I'm trying to add a label to center of it. 我已经创建了一个新的“单视图应用程序”项目,输入了一个main.Storyboard,我正在尝试添加一个标签到它的中心。 On a preview of this storyboard for 4-inch iPhone, the label isn't centered, even when I force storyboard to use 3.5, 4, or 4.7-inch iPhones. 在4英寸iPhone的故事板预览中,标签不居中,即使我强迫故事板使用3.5,4或4.7英寸iPhone。 Adding constraints makes no difference. 添加约束没有区别。 What am I doing wrong? 我究竟做错了什么?

If you want to center the label vertically and horizontally, you can use Align option at the storyboard. 如果要垂直和水平居中标签,可以在故事板上使用“对齐”选项。 On your storyboard's bottom right corner, there are four options and the first one is Align option, selecting it will give you to choose the alignment for your object as follows, 在故事板的右下角,有四个选项,第一个是Align选项,选择它会让您选择对象的对齐方式,如下所示,

对齐选项

Here in the screenshot, you can see that I have selected two options if I want to center my object in both dimension. 在屏幕截图中,如果我想在两个维度中居中对象,您可以看到我选择了两个选项。 You can choose either one of them or both based on your requirements and press Add 2 constraints button and it will work consistently for any sized screen. 您可以根据您的要求选择其中一个或两个,然后按添加2约束按钮,它将适用于任何大小的屏幕。 However make sure to select the object you want to center before selecting the Align option. 但是,在选择“ 对齐”选项之前,请确保选择要居中的对象。

Try using the reset to suggested constraints. 尝试使用重置建议约束。 It works quite well for simple layout. 它适用于简单的布局。 Otherwise, you just have to fine tune your constraints 否则,您只需要微调约束 重置为建议的约束。

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

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