Skip to content

Commit

Permalink
added assorted superviewMargins and superviewSafeArea relatable short…
Browse files Browse the repository at this point in the history
…cuts
  • Loading branch information
Matthew Crenshaw committed Feb 10, 2018
1 parent 2c8262e commit 9b5516e
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions Source/ConstraintMakerRelatable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@ public class ConstraintMakerRelatable {
}
return self.relatedTo(other, relation: .equal, file: file, line: line)
}

#if os(iOS) || os(tvOS)
@available(iOS 9.0, *)
@discardableResult
public func equalToSuperviewMargins(_ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable {
guard let other = self.description.item.superview else {
fatalError("Expected superview but found nil when attempting make constraint `equalToSuperviewMargins`.")
}
return self.relatedTo(other.layoutMarginsGuide, relation: .equal, file: file, line: line)
}

@available(iOS 11.0, *)
@discardableResult
public func equalToSuperviewSafeArea(_ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable {
guard let other = self.description.item.superview else {
fatalError("Expected superview but found nil when attempting make constraint `equalToSuperviewSafeArea`.")
}
return self.relatedTo(other.safeAreaLayoutGuide, relation: .equal, file: file, line: line)
}
#endif

@discardableResult
public func lessThanOrEqualTo(_ other: ConstraintRelatableTarget, _ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable {
Expand All @@ -97,6 +117,26 @@ public class ConstraintMakerRelatable {
}
return self.relatedTo(other, relation: .lessThanOrEqual, file: file, line: line)
}

#if os(iOS) || os(tvOS)
@available(iOS 9.0, *)
@discardableResult
public func lessThanOrEqualToSuperviewMargins(_ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable {
guard let other = self.description.item.superview else {
fatalError("Expected superview but found nil when attempting make constraint `lessThanOrEqualToSuperviewMargins`.")
}
return self.relatedTo(other.layoutMarginsGuide, relation: .lessThanOrEqual, file: file, line: line)
}

@available(iOS 11.0, *)
@discardableResult
public func lessThanOrEqualToSuperviewSafeArea(_ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable {
guard let other = self.description.item.superview else {
fatalError("Expected superview but found nil when attempting make constraint `lessThanOrEqualToSuperviewSafeArea`.")
}
return self.relatedTo(other.safeAreaLayoutGuide, relation: .lessThanOrEqual, file: file, line: line)
}
#endif

@discardableResult
public func greaterThanOrEqualTo(_ other: ConstraintRelatableTarget, _ file: String = #file, line: UInt = #line) -> ConstraintMakerEditable {
Expand All @@ -110,4 +150,24 @@ public class ConstraintMakerRelatable {
}
return self.relatedTo(other, relation: .greaterThanOrEqual, file: file, line: line)
}

#if os(iOS) || os(tvOS)
@available(iOS 9.0, *)
@discardableResult
public func greaterThanOrEqualToSuperviewMargins(_ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable {
guard let other = self.description.item.superview else {
fatalError("Expected superview but found nil when attempting make constraint `greaterThanOrEqualToSuperviewMargins`.")
}
return self.relatedTo(other.layoutMarginsGuide, relation: .greaterThanOrEqual, file: file, line: line)
}

@available(iOS 11.0, *)
@discardableResult
public func greaterThanOrEqualToSuperviewSafeArea(_ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable {
guard let other = self.description.item.superview else {
fatalError("Expected superview but found nil when attempting make constraint `greaterThanOrEqualToSuperviewSafeArea`.")
}
return self.relatedTo(other.safeAreaLayoutGuide, relation: .greaterThanOrEqual, file: file, line: line)
}
#endif
}

0 comments on commit 9b5516e

Please sign in to comment.