简体   繁体   English

Xcode 8:自动布局问题

[英]Xcode 8 : Auto Layout Issue

I have few problems with the auto layout. 我在自动布局方面遇到了一些问题。 It looks perfect in Xcode for every iPhone models, but when I try on my iPhone 5S, the buttons don't look same as with my main storyboard. 在每种iPhone型号的Xcode中,它看起来都很完美,但是当我尝试使用iPhone 5S时,按钮的外观与我的主故事板上的有所不同。 It works perfectly only for iPhone 7 and 7 plus sizes. 它仅适用于iPhone 7和7及以上尺寸。

在此处输入图片说明

I used "Reset to suggested constraints" function. 我使用了“重置为建议的约束”功能。 The Tic tac toe board is imageView and I have 9 buttons on it. 井字游戏板是imageView,上面有9个按钮。 These buttons don't look properly for iPhone 5s and 4s sizes. 这些按钮不适用于iPhone 5s和4s尺寸。 How can I fix it? 我该如何解决?

For the board you can user a view with black background color and for the buttons, put the buttons inside the board view by giving their height and width according to the height and width of the view. 对于木板,您可以使用黑色背景色的视图,对于按钮,可以通过根据视图的高度和宽度指定按钮的高度和宽度,将按钮放在木板视图内。 For example, button's height should be equal to (1/3 of view's height- (the spacing between the button)/2) and similarly do this for the width. 例如,按钮的高度应等于(视图高度的1/3-(按钮之间的间距)/ 2),并类似地对宽度执行此操作。

For the position of the buttons, position them to horizontal and vertical to board view and change the constraints multiplier accordingly(may be 1/2 for the first button , 1 for the center button and 3/2 for the third button) and similarly do this for the vertical position of the button. 对于按钮的位置,将它们置于水平和垂直于板视图的位置,并相应地更改约束乘数(对于第一个按钮可以为1/2,对于中央按钮为1,对于第三按钮为3/2),并且类似地这是按钮的垂直位置。

Set the board view constraint to the main view, so now whenever the screen size changes your buttons and view will automatically be adjusted. 将面板视图约束设置为主视图,因此现在只要屏幕尺寸更改,您的按钮和视图就会自动进行调整。

If you didn't understand my answer or need more clarity or help, just comment on this tagging me. 如果您不理解我的答案,或者需要更多说明或帮助,请对此标签发表评论。

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

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