简体   繁体   English

Xcode 8约束

[英]Xcode 8 constraints

I was coding in swift on the latest version of Xcode (as of 12/1/17). 我正在快速地对最新版本的Xcode(截至17年1月1日)进行编码。 Since I'm new to coding in swift, I was unable to figure out a way to make my app compatible for all screen sizes. 由于我不熟悉快速编码,因此无法找到一种使我的应用程序兼容所有屏幕尺寸的方法。 While building the app, my "View as" was set as iPhone SE. 在构建应用程序时,我的“查看为”设置为iPhone SE。 Now when I try running the program in another screen size, the size of the buttons, textfields and labels aren't in proportion. 现在,当我尝试以其他屏幕尺寸运行程序时,按钮,文本字段和标签的尺寸不成比例。 I found others with the same problem but none were able to answer my problem in a manner that I'd understand. 我发现其他人也遇到相同的问题,但没有人能够以我所理解的方式回答我的问题。 This is one of the many frames on my storyboard that seems to be having the problem. 这是我的情节提要上似乎有问题的众多框架之一。 I tried to click on the "Reset to suggested constraints" button but that only seemed to mess up the screen. 我试图单击“重置为建议的约束”按钮,但这似乎只会使屏幕混乱。 It would be helpful if you'd be able to help me with this specific frame. 如果您能够在此特定框架方面为我提供帮助,将会很有帮助。

Xcode 8 provide efficient way to use autolayout. Xcode 8提供了使用自动布局的有效方法。

You can check the video also. 您也可以查看视频。 This works for me fine. 这对我来说很好。

https://youtu.be/lx1NRHRMwUg https://youtu.be/lx1NRHRMwUg

Whenever I have run into layout problems, I always find it easiest to delete them all, and start again. 每当遇到布局问题时,我总是很容易将其全部删除,然后重新开始。 If you leave some in place, and start trying to fix others it can be very hard to tell what's going on. 如果您将其中的一些保留在原处,然后开始尝试修复其他问题,那么很难说出是怎么回事。

The key thing with constraints is to keep it simple. 有约束的关键是保持简单。 If you only have 6 labels which are all in one column, then you can set the constraints for the first one (Displacement) in your example - make sure you're happy with the positioning, and then align all of the others to have the same leading edge, and give them Top & Bottom space constraints . 如果一列中只有6个标签,则可以在示例中为第一个标签(位移)设置约束-确保对定位满意,然后将所有其他标签对齐以使相同的前缘,并赋予它们顶部和底部的空间约束。 This means if you decide to move them all out from the edge, you only have to change one. 这意味着,如果您决定将它们全部从边缘移出,则只需更改一个即可。

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

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