Skip to content

Commit 716212a

Browse files
authored
Merge pull request #178 from willonboy/zt/dev
Add the `SteviaLayoutConstraint` class to allow the removal of constraints added by Stevia.
2 parents 74ea064 + 234033e commit 716212a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Sources/Stevia/Stevia+Constraints.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
#if canImport(UIKit)
1010
import UIKit
1111

12+
public class SteviaLayoutConstraint: NSLayoutConstraint {
13+
public static defaultPriority:Float = UILayoutPriority.defaultHigh + 1
14+
}
15+
16+
1217
// MARK: - Shortcut
1318

1419
public extension UIView {
@@ -76,11 +81,11 @@ public extension UIView {
7681
attribute attr2: NSLayoutConstraint.Attribute? = nil, // Not an attribute??
7782
multiplier: Double = 1,
7883
constant: Double = 0) -> NSLayoutConstraint {
79-
let c = NSLayoutConstraint(item: view1, attribute: attr1,
84+
let c = SteviaLayoutConstraint(item: view1, attribute: attr1,
8085
relatedBy: relatedBy,
8186
toItem: view2, attribute: ((attr2 == nil) ? attr1 : attr2! ),
8287
multiplier: CGFloat(multiplier), constant: CGFloat(constant))
83-
c.priority = UILayoutPriority(rawValue: UILayoutPriority.defaultHigh.rawValue + 1)
88+
c.priority = UILayoutPriority(rawValue: SteviaLayoutConstraint.defaultPriority)
8489
return c
8590
}
8691

@@ -98,8 +103,7 @@ public extension UIView {
98103
*/
99104
var userAddedConstraints: [NSLayoutConstraint] {
100105
return constraints.filter { c in
101-
guard let cId = c.identifier else { return true }
102-
return !cId.contains("UIView-Encapsulated-Layout") && !cId.contains("Margin-guide-constraint")
106+
c is SteviaLayoutConstraint
103107
}
104108
}
105109
}

0 commit comments

Comments
 (0)