Xcode 6 Storyboard 无法居中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26958811/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:11:09  来源:igfitidea点击:

Xcode 6 Storyboard can't center

iosxcodestoryboard

提问by Artem Zaytsev

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. 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. Adding constraints makes no difference. What am I doing wrong?

我在尝试将一个对象放在情节提要中时遇到问题。我创建了一个新的“单视图应用程序”项目,输入了一个 main.Storyboard,我试图在它的中心添加一个标签。在 4 英寸 iPhone 的故事板预览中,即使我强制故事板使用 3.5、4 或 4.7 英寸 iPhone,标签也不居中。添加约束没有区别。我究竟做错了什么?

回答by ldindu

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,

如果要垂直和水平地将标签居中,可以使用故事板中的对齐选项。在故事板的右下角,有四个选项,第一个是对齐选项,选择它会让您选择对象的对齐方式,如下所示,

Alignment option

对齐选项

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 constraintsbutton and it will work consistently for any sized screen. However make sure to select the object you want to center before selecting the Alignoption.

在屏幕截图中,如果我想在两个维度中居中对象,您可以看到我选择了两个选项。您可以根据您的要求选择其中一个或两个,然后按添加 2 个约束按钮,它会在任何大小的屏幕上始终如一地工作。但是,请确保在选择“对齐”选项之前选择要居中的对象。

回答by Kalenda

Try using the reset to suggested constraints. It works quite well for simple layout. Otherwise, you just have to fine tune your constraints reset to suggested constraints.

尝试使用重置为建议的约束。它适用于简单的布局。否则,你只需要微调你的约束 重置为建议的约束。