什么是水平排列的5个按钮与自动布局的最佳方法 [英] What is the best approach for horizontally aligning 5 buttons with Autolayout

查看:1558
本文介绍了什么是水平排列的5个按钮与自动布局的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个小菜鸟的风格问题,但我找不到这方面有任何问题,我要在我的视图控制器水平对齐多个按钮。

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和&lt分开=宽度变化的约束优先等。第二个不具有右舷对齐很好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.

步骤(我们只考虑在这里横向约束):


  1. 从第一个按钮添加导致约束到上海华(或左侧兄弟视图)。

  2. 添加的水平间距约束:

    • 第一个按钮和第二个按钮。

    • 第二个按钮和第三个按钮。

    • 第三个按钮和第四个按钮。

    • 第四个按钮和第五个按钮。


  • 第一个按钮和第二个按钮。

  • 第二个按钮和第三个按钮。

  • 第三个按钮和第四个按钮。

  • 第四个按钮和第五个按钮。

如果您按照这种方法,你不必添加对齐按钮额外的意见。请看下面的截图了解这更好的。

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个按钮与自动布局的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆