I have a grid made of iOS buttons (think Sudoku). I assigned each button to have aspect ratio 1:1. To further ensure their equality, I have made each button have width = height constraint set.
我有一个由iOS按钮组成的网格(想想数独)。我指定每个按钮的宽高比为1:1。为了进一步确保它们的相等性,我已经使每个按钮都设置了width = height约束。
However, when I look at the buttons, some of them have 44x45, while others have 44x44 (as expected).
但是,当我看按钮时,其中一些有44x45,而有些则有44x44(如预期的那样)。
Is there a constraint that I'm missing or is there a workaround that can guarantee my buttons are perfect squares.
是否存在我缺少的约束,或者是否存在可以保证我的按钮是完美正方形的解决方法。
1 个解决方案
#1
1
This is probably happening because you have other constraints affecting the views too. For eg. You might have put these in a container view and specified container views width or made container view's width equal to the width of screen.
这可能正在发生,因为您还有其他影响视图的约束。例如。您可能已将这些放入容器视图和指定的容器视图宽度或使容器视图的宽度等于屏幕的宽度。
Now when these square view fill the container view, then there is some extra space left say for eg like 7 points. What autolayout does is that it adds these 7 points making some of your squares wider by 1 point.
现在,当这些方形视图填充容器视图时,则剩下一些额外的空间,例如7点。自动布局的作用是它增加了这7个点,使你的一些方格更宽1点。
This can be fixed by providing the correct constraints for the container view.
这可以通过为容器视图提供正确的约束来解决。
#1
1
This is probably happening because you have other constraints affecting the views too. For eg. You might have put these in a container view and specified container views width or made container view's width equal to the width of screen.
这可能正在发生,因为您还有其他影响视图的约束。例如。您可能已将这些放入容器视图和指定的容器视图宽度或使容器视图的宽度等于屏幕的宽度。
Now when these square view fill the container view, then there is some extra space left say for eg like 7 points. What autolayout does is that it adds these 7 points making some of your squares wider by 1 point.
现在,当这些方形视图填充容器视图时,则剩下一些额外的空间,例如7点。自动布局的作用是它增加了这7个点,使你的一些方格更宽1点。
This can be fixed by providing the correct constraints for the container view.
这可以通过为容器视图提供正确的约束来解决。