Explorar o código

Add ConstraintMaker shortcuts for superview access (#341)

Added two new shortcuts for access superview in ConstraintMakerRelatable
`greaterThanOrEqualToSuperview`
`lessThanOrEqualToSuperview`
Txai Wieser %!s(int64=9) %!d(string=hai) anos
pai
achega
180ff1477e
Modificáronse 1 ficheiros con 15 adicións e 0 borrados
  1. 15 0
      Source/ConstraintMakerRelatable.swift

+ 15 - 0
Source/ConstraintMakerRelatable.swift

@@ -87,9 +87,24 @@ public class ConstraintMakerRelatable {
         return self.relatedTo(other, relation: .lessThanOrEqual, file: file, line: line)
     }
     
+    @discardableResult
+    public func lessThanOrEqualToSuperview(_ file: String = #file, _ line: UInt = #line) -> ConstraintMakerEditable {
+        guard let other = self.description.view.superview else {
+            fatalError("Expected superview but found nil when attempting make constraint `lessThanOrEqualToSuperview`.")
+        }
+        return self.relatedTo(other, relation: .lessThanOrEqual, file: file, line: line)
+    }
+    
     @discardableResult
     public func greaterThanOrEqualTo(_ other: ConstraintRelatableTarget, _ file: String = #file, line: UInt = #line) -> ConstraintMakerEditable {
         return self.relatedTo(other, relation: .greaterThanOrEqual, file: file, line: line)
     }
     
+    @discardableResult
+    public func greaterThanOrEqualToSuperview(_ file: String = #file, line: UInt = #line) -> ConstraintMakerEditable {
+        guard let other = self.description.view.superview else {
+            fatalError("Expected superview but found nil when attempting make constraint `greaterThanOrEqualToSuperview`.")
+        }
+        return self.relatedTo(other, relation: .greaterThanOrEqual, file: file, line: line)
+    }
 }