本文介绍了自动布局问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个按钮的视图.我添加了自动布局.但是iPhone 8 plus的底部空间要比iPhone 4s多.我想在所有iPhone中保持顶部和底部的间距比例相同.如何解决?

I have a view with two button. I have added auto-layout. But bottom space is more in iPhone 8 plus than iPhone 4s.I want to keep the spacing ratio of top and bottom same in all iPhone. How to fix it ?

推荐答案

已更新

对于特定比率:据我所知,我们可以给Centre Vertically Constraints乘数.在这里,顶部和底部空间的比例在所有iPhone系列中都相同.我将乘数设为1.4

For Specific Ratio : To my understood, We can give Multiplier for Centre Vertically Constraints. Here ratio of top and bottom space will be same in all iPhone series. I gave Multiplier as 1.4

=================================

==================================

我知道那里有几个答案.但是,没有人使用UIStackView添加两个简单的按钮.

I know having several answers there. But, no one used UIStackView to add two simple buttons.

拖动两个UIButton,选择两个UIButton,然后从此处单击Embed in Stack图标.

Drag two UIButton, select that two UIButtons, click Embed in Stack icon from here.

Stackview属性

为UIStackView提供以下内容,

Give following things for UIStackView,

Attributes Inspector中将Axis设置为Horizontal,将Distribution设置为Fill Equally,将Spacing设置为10

Set Axis as Horizontal, Distribution as Fill Equally, Spacing as 10 in Attributes Inspector

Stackview约束1

赋予该UIStackView约束,选中/取消选中边距,向左和向右= 0,高度为30.

Give constraints for that UIStackView, Check/Uncheck Margins, Left and Right = 0, Height as 30.

Stackview约束2

仍然,某些约束未得到满足.按住Control并单击,然后单击StackView并拖动到SuperView,将弹出黑色.选择Center Vertically in container.

Still, some constraints are not satisfied. Press Control and hold it, Click StackView and Drag to SuperView, you will get black pop up. Choose Center Vertically in container.

Stackview约束自定义

如果要更改UIButton或底部空间的高度,请单击UIStackView,然后在Size Inspector中,可以更改高度或上下移动.

If you want to change height of UIButton or Bottom Space, click UIStackView and in Size Inspector, you can change height or move up/down.

这篇关于自动布局问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-15 09:05