按钮并没有达到预期的iOS自动布局

时间:2021-02-22 20:22:32

I'm trying to make "Two Equal-Width Buttons" As it's described in Apple Auto Layout Guide.

我正在尝试制作“两个等宽按钮”,正如苹果汽车布局指南中所描述的那样。

https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/ViewswithIntrinsicContentSize.html#//apple_ref/doc/uid/TP40010853-CH13-SW1

https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/ViewswithIntrinsicContentSize.html / / apple_ref / doc / uid / TP40010853-CH13-SW1

And it looks ok in preview of interface builder (Main.storyboard).But when I try to change devices i see that width is different on some devices. How can i fix that ? How can I make equal width of buttons for all devices by using constraints or another techniques?

它在界面构建器(Main.storyboard)的预览中看起来还可以。但当我尝试改变设备时,我发现某些设备的宽度不同。我怎么解决呢?如何使用约束或其他技术使所有设备的按钮宽度相等?

Updated Examples:

更新的例子:

width is ok

宽度是可以的

按钮并没有达到预期的iOS自动布局

width is not ok

宽度是不可以

按钮并没有达到预期的iOS自动布局

Width is ok

宽度是可以的

Width is not ok

宽度是不可以

2 个解决方案

#1


1  

There is not problem with the width of your buttons. Because of difference of 0.5 point between two buttons, it may not be showing you equal width.

按钮的宽度没有问题。由于两个按钮之间有0.5个点的差异,它可能不会显示你的宽度相等。

Just check width of both button manually, there may not be difference between them, more than 1 point.

只需手动检查两个按钮的宽度,它们之间可能没有差别,超过1个点。

Look at this snapshots:

看看这个快照:

iPhone 5

按钮并没有达到预期的iOS自动布局

iPhone 8

按钮并没有达到预期的iOS自动布局

iPhone X

按钮并没有达到预期的iOS自动布局

按钮并没有达到预期的iOS自动布局

按钮并没有达到预期的iOS自动布局

#2


1  

Put your buttons inside a UIStackView horizontal and set distribution attribute to FILL EQUALLY

将按钮放在UIStackView水平视图中,并设置distribution属性以均匀填充

Look this tutorial for more examples.

查看本教程以获得更多示例。

#1


1  

There is not problem with the width of your buttons. Because of difference of 0.5 point between two buttons, it may not be showing you equal width.

按钮的宽度没有问题。由于两个按钮之间有0.5个点的差异,它可能不会显示你的宽度相等。

Just check width of both button manually, there may not be difference between them, more than 1 point.

只需手动检查两个按钮的宽度,它们之间可能没有差别,超过1个点。

Look at this snapshots:

看看这个快照:

iPhone 5

按钮并没有达到预期的iOS自动布局

iPhone 8

按钮并没有达到预期的iOS自动布局

iPhone X

按钮并没有达到预期的iOS自动布局

按钮并没有达到预期的iOS自动布局

按钮并没有达到预期的iOS自动布局

#2


1  

Put your buttons inside a UIStackView horizontal and set distribution attribute to FILL EQUALLY

将按钮放在UIStackView水平视图中,并设置distribution属性以均匀填充

Look this tutorial for more examples.

查看本教程以获得更多示例。