我知道这是一个新手风格的小问题,但我找不到任何主题,我必须在视图控制器中水平对齐多个按钮.
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 和 <= 宽度更改约束优先级等分开.第二个没有 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 ?
谢谢!
你只需要在相邻按钮之间给出前导、尾随和等宽约束.
You just need to give leading, trailing and equal-widths constraints between adjacent buttons.
步骤(这里我们只考虑水平约束):
如果您采用这种方法,则无需添加额外的视图来对齐按钮.请查看下面的屏幕截图以更好地理解这一点.
If you follow this approach, you need not add extra views to align the buttons. Please see the screenshots below for understanding this better.
这篇关于使用自动布局水平对齐 5 个按钮的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!