简体   繁体   English

在 Swift (Xcode) 中为不同的屏幕尺寸创建约束

[英]create constraint for different screen sizes in Swift (Xcode)

I'm trying to make a Tic-Tac-Toe game and almost it's finished but I have a problem with UI and setting constraints for different screen sizes.我正在尝试制作 Tic-Tac-Toe 游戏,几乎完成了,但我在 UI 和为不同屏幕尺寸设置约束方面遇到了问题。 for example, I have a UIView in the bottom of the screen that has height constraint equal to superView but with multiple under 1 and an under-zero constant value and it looks great in some screen sizes like iPhone (XS max - Xs - 8 - 8plus) but it's not looking good in iPhone (SE or 5s) how can I make or edit constraint just for these screen sizes (4 inches) (SE - 5S)??例如,我在屏幕底部有一个 UIView,它的高度约束等于 superView,但倍数低于 1 和低于零的常数值,它在某些屏幕尺寸(如 iPhone)中看起来很棒(XS max - Xs - 8 - 8plus)但在 iPhone(SE 或 5s)中看起来不太好,我怎样才能为这些屏幕尺寸(4 英寸)(SE - 5S)制作或编辑约束?

NOTE: I know about size classes in Swift (compact Any) but this concept doesn't help me in this situation because of all screen sizes in portrait mode is same each other注意:我知道 Swift(紧凑型任何)中的尺寸等级,但这个概念在这种情况下对我没有帮助,因为纵向模式下的所有屏幕尺寸都是相同的

The situation you've described is not really understandable, but for adjusting the layout for some screen sizes you can have outlets for some constraints, and change those values in your code if the screen size is small.您描述的情况并不是真正可以理解的,但是为了调整某些屏幕尺寸的布局,您可以有一些约束的出口,如果屏幕尺寸很小,可以在代码中更改这些值。 You can get the screen size from UIScreen like this UIScreen.main.bounds.size.height您可以像这样从 UIScreen 获取屏幕尺寸UIScreen.main.bounds.size.height

This is not an approach to apply all the time though.不过,这并不是一种一直适用的方法。 In general, you should try to layout your views in a way that it is not necessary.通常,您应该尝试以不必要的方式布局视图。 I am sure if you upload screenshots of your view on big and small screens, and a screenshot of how is your layout done and what constraints do you have, you will get more help.我相信如果你上传你的视图在大屏幕和小屏幕上的截图,以及你的布局是如何完成的以及你有什么限制的截图,你会得到更多的帮助。

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

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