AutoLayoutBuilder 2.0.0

AutoLayoutBuilder 2.0.0

测试已测试
语言语言 SwiftSwift
许可协议 MIT
发布上次发布2015年11月
SPM支持 SPM

Marc Baldwin 维护。



  • 作者
  • marcbaldwin

AutoLayoutBuilder

苹果自动布局的 Swift DSL

示例 | 安装

为什么使用 AutoLayoutBuilder?

  • 表达性强 - 约束条件极其易读且简洁
  • 速度快 - 编写更少的代码,而且更短
  • 安全可靠 - 无效的约束是编译器错误
  • 灵活 - 属性作为参数提供,因此可以在运行时变更

示例

// Example: Left equals right
let constraints = view1[.Left] == view2[.Right]

// Example: Center X of view1, view2 and view3 equal to center X of view4
let constraints = Group(view1, view2, view3)[.CenterX] == view4[.CenterX]

// Example: Left equals left with margin
let constraints = view1[.Left] == view2[.Left] + 10

// Example: Equal X and Y centers
let constraints = view1[.Center] == view2[.Center]

// Example: Equal X centers with margin
let constraints = view1[.CenterX] == view2[.CenterX] - 10

// Example: CenterY equals Top with margin
let constraints = view1[.CenterY] == view2[.Top] - 10

// Example: Equal edges
let constraints = view1[.Edges] == view2[.Edges]

// Example: Equal edges with margin
let constraints = view1[.Edges] == view2[.Edges] - 5

// Example: Equal sizes
let constraints = view1[.Size] == view2[.Size]

// Example: Greater than or equal sizes
let constraints = view1[.Size] >= view2[.Size]

// Example: Relative sizes
let constraints = view1[.Size] == view2[.Size] * 0.5

// Example: Fixed size
let constraints = view1[.Size] == CGSize(width: 50, height: 20)

// Example: Equal widths
let constraints = view1[.Width] == view2[.Width]

// Example: Equal width and height
let constraints = view1[.Width] == view1[.Height]

// Example: Left to right layout
let constraints = .Horizontal ~ view1 | view2 | view3

// Example: Left to right layout with margins
let constraints = .Horizontal ~ view1 | 5 | view2 | 5 | view3

// Example: Leading to trailing layout with margins
let constraints = .LeadingToTrailing ~ view1 | 5 | view2 | 5 | view3

// Example: Top to bottom layout with margins
let constraints = .Vertical ~ view1 | 5 | view2 | 5 | view3

// Example: Top equals top layout guide's bottom
let constraints = view1[.Top] == viewController.layoutGuide.top[.Bottom]

// Example: Bottom equals bottom layout guide's top with margin
let constraints = view1[.Bottom] == viewController.layoutGuide.bottom[.Top] - 5

安装