测试已测试 | ✗ |
Lang语言 | SwiftSwift |
许可 | MIT |
发布最新发布 | 2017年6月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 kaizeiyimi 维护。
使用一些 Swift 的神奇功能,提供了一种非常简洁清晰的代码中制作约束的方式。
由于 Swift 3 是必需的,您需要 XCode 8 及以上。如果您需要 Swift 2.3 版本,请使用 1.3.0。
当前最新版本是 2.1.1。
您必须了解 'left.attr = right.attr * m + c' 对 AutoLayout 的含义。
import XAutoLayout
// use `=/`` to make composite equal witch creates an array of NSLayoutConstraint
NSLayoutConstraint.activateConstraints( v1.xEdge =/ [10,5,-10,-20] )
// use 'xmakeConstraints' to make constraints. constraints can be adjusted by 'direction'
// direction is default to 'LeadingToTrailing' and autoActive is default to 'true'
xmakeConstraints(.RightToLeft, autoActive: true) {
v2.xSize =/ [50, view.xHeight.xc(-80)]
// since the direction is 'RightToLeft', the "v2.xLeading =/ 10" will be adjusted as "v2.xRight =/ -10"
[v2.xTop, v2.xLeading] =/ [20, 10.xp(750)]
// notice that in 'v2.xLeading =/ 10' the right var is a number 10,
// since no view is specified, superview of v2 will be used as second item, and secondAttr is same as firstAttr.
// so the result is same as "v2.xLeading =/ v2.superview.xLeading.c(10)"
}
// and you should know "v.xHeight =/ 20" will not use superview, because height and width are dimension not anchor.
// we can also adjust constraint's constaint, multiplier and priority
v.xWidth =/ view.xWidth.xm(2).xc(-20).xp(750)
它易于阅读和编写。不是吗?
XFirstItem
协议并实现 xGenerate
。func xGenerate() -> XAttribute {
return XAttribute(item: yourItem, attr: yourAttr)
}
yourItem
和 yourAttr
是约束的第一项和第一属性。
public func xGenerateX() -> XAttributeX {
return XAttributeX(item: nil, attr: .NotAnAttribute, constant: CGFloat(("\(self)" as NSString).doubleValue))
}
项和属性将是约束的第二项和第二属性。如果您需要,您可以提供常量、乘数和优先级。但您必须了解您所做的事情。
API 对开发者来说不友好。太长且太复杂。希望 XAutoLayout 让我们的工作更轻松。