本文為投稿文章,作者:qianbin(GitHub)
Demo:

AutoLinearLayoutView 完全基於 Auto Layout 實現,支持 iOS 7 及以上系統。它可以直接在 Interface Builder 中修改屬性,便於在 Xib/Storyboard 中快速搭建界面:

與 UIStackView 相比,它多了 Insets 屬性,少了 Distribution 和 Baseline Relative 屬性。Insets 對 UIStackView 而言幾乎無解(額外約束會沖突);而 Distribution 與 Baseline Relative 對 AutoLinearLayoutView 來說,只需輕鬆添加額外約束即可實現。
它充分考慮了內部隱含約束的優先級:
此外,AutoLinearLayoutView 支持動態添加/移除子 View。具體實現與 Demo 請訪問:https://github.com/qianbin/AutoLinearLayoutView