什么是水平对齐5个按钮与自动布局的最佳方法 [英] What is the best approach for horizontally aligning 5 buttons with Autolayout
问题描述
我知道这是一个新手风格的问题,但我找不到任何主题,我必须水平对齐多个按钮在我的视图控制器。
I know this is a little newbie style question but I couldn't find any subject about this and I have to horizontally align multiple buttons in my view controller.
我试图2方法第一个是用UIViews和< = width改变约束优先级和其他。第二个没有UIViews,但按钮对齐在右舷很好。我已经看了斯坦福汽车布局课。但我找不到任何解决方案。我不知道如何对齐多个按钮或视图,有人可以帮助我学习和解决这个问题?
I tried to 2 approach first one is separate them with UIViews and <= width changed constraints priority and others. Second one doesn't have UIViews but buttons aligned in starboard very well. I already watched Stanford auto layout lessons. But I couldn't find any solution about this. I don't know how to approach to align multiple buttons or views can someone help me to learn and solve this problem ?
谢谢!
Thanks !
推荐答案
你只需要在相邻按钮之间给出前导,尾随和等宽的约束。
You just need to give leading, trailing and equal-widths constraints between adjacent buttons.
步骤(我们只考虑横向限制):
- 在第一个按钮之间添加水平间距约束:
- 第一个按钮和第二个按钮。
- 第二个按钮和第三个按钮。
- 第三个按钮和第四个按钮。 $ b
- 第四个按钮和第五个按钮
- Add leading constraint from the first button to the superview (or left-side sibling view).
- Add horizontal spacing constraint between:
- First button and second button.
- Second button and third button.
- Third button and fourth button.
- Fourth button and fifth button.
- 第一个按钮和第二个按钮。 li>
- 第二个按钮和第三个按钮。
- 第三个按钮和第四个按钮。
- 第四个按钮和第五个按钮。
方法,您不需要添加额外的视图来对齐按钮。请参阅下面的屏幕截图,了解详情。
If you follow this approach, you need not add extra views to align the buttons. Please see the screenshots below for understanding this better.
< a href =https://i.stack.imgur.com/lkXuG.png =nofollow noreferrer>
这篇关于什么是水平对齐5个按钮与自动布局的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!