mirror of https://github.com/SnapKit/SnapKit
Finish support for UILayoutGuide via Constraint MAker
This commit is contained in:
parent
dc304472aa
commit
d32a47f0dd
|
@ -49,12 +49,12 @@ extension ConstraintDSL {
|
|||
private var labelKey: UInt8 = 0
|
||||
|
||||
|
||||
public protocol ConstraintAttributesDSL: ConstraintDSL {
|
||||
public protocol ConstraintBasicAttributesDSL : ConstraintDSL {
|
||||
}
|
||||
extension ConstraintAttributesDSL {
|
||||
extension ConstraintBasicAttributesDSL {
|
||||
|
||||
// MARK: Basics
|
||||
|
||||
|
||||
public var left: ConstraintItem {
|
||||
return ConstraintItem(target: self.target, attributes: ConstraintAttributes.left)
|
||||
}
|
||||
|
@ -107,6 +107,12 @@ extension ConstraintAttributesDSL {
|
|||
return ConstraintItem(target: self.target, attributes: ConstraintAttributes.center)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public protocol ConstraintAttributesDSL : ConstraintBasicAttributesDSL {
|
||||
}
|
||||
extension ConstraintAttributesDSL {
|
||||
|
||||
// MARK: Baselines
|
||||
|
||||
@available(*, deprecated:3.0, message:"Use .lastBaseline instead")
|
||||
|
|
|
@ -31,6 +31,27 @@
|
|||
@available(iOS 9.0, *)
|
||||
public struct ConstraintLayoutGuideDSL: ConstraintAttributesDSL {
|
||||
|
||||
@discardableResult
|
||||
public func prepareConstraints(_ closure: (_ make: ConstraintMaker) -> Void) -> [Constraint] {
|
||||
return ConstraintMaker.prepareConstraints(item: self.guide, closure: closure)
|
||||
}
|
||||
|
||||
public func makeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) {
|
||||
ConstraintMaker.makeConstraints(item: self.guide, closure: closure)
|
||||
}
|
||||
|
||||
public func remakeConstraints(_ closure: (_ make: ConstraintMaker) -> Void) {
|
||||
ConstraintMaker.remakeConstraints(item: self.guide, closure: closure)
|
||||
}
|
||||
|
||||
public func updateConstraints(_ closure: (_ make: ConstraintMaker) -> Void) {
|
||||
ConstraintMaker.updateConstraints(item: self.guide, closure: closure)
|
||||
}
|
||||
|
||||
public func removeConstraints() {
|
||||
ConstraintMaker.removeConstraints(item: self.guide)
|
||||
}
|
||||
|
||||
public var target: AnyObject? {
|
||||
return self.guide
|
||||
}
|
||||
|
|
|
@ -60,6 +60,29 @@ class SnapKitTests: XCTestCase {
|
|||
|
||||
}
|
||||
|
||||
func testGuideMakeConstraints() {
|
||||
let v1 = View()
|
||||
let g1 = UILayoutGuide()
|
||||
|
||||
self.container.addSubview(v1)
|
||||
self.container.addLayoutGuide(g1)
|
||||
|
||||
v1.snp.makeConstraints { (make) -> Void in
|
||||
make.top.equalTo(g1.snp.top).offset(50)
|
||||
make.left.equalTo(g1.snp.top).offset(50)
|
||||
return
|
||||
}
|
||||
|
||||
XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints installed")
|
||||
|
||||
g1.snp.makeConstraints { (make) -> Void in
|
||||
make.edges.equalTo(v1)
|
||||
return
|
||||
}
|
||||
|
||||
XCTAssertEqual(self.container.snp_constraints.count, 6, "Should have 6 constraints installed")
|
||||
}
|
||||
|
||||
func testMakeImpliedSuperviewConstraints() {
|
||||
let v1 = View()
|
||||
let v2 = View()
|
||||
|
|
Loading…
Reference in New Issue