Skip to content

Commit 79b34e8

Browse files
author
Steve Kim
committed
Support layout for UILayoutGuide
1 parent 3082f72 commit 79b34e8

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

SimpleLayout/Classes/SimpleLayoutObject.swift

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ public class SimpleLayoutObject: NSObject {
3333
}
3434

3535
@discardableResult
36-
public func bottom(by target: UIView? = nil, attribute: NSLayoutAttribute = .bottom, multiplier: CGFloat = 1.0, _ constant: CGFloat = 0) -> SimpleLayoutObject {
36+
public func bottom(by target: Any? = nil, attribute: NSLayoutAttribute = .bottom, multiplier: CGFloat = 1.0, _ constant: CGFloat = 0) -> SimpleLayoutObject {
3737
removeBottom()
3838

39-
let targetView = target != nil ? target! : view.superview
39+
let targetView = target != nil ? target! : view.superview as Any
4040
constraints.bottom = NSLayoutConstraint(item: view, attribute: .bottom, relatedBy: .equal, toItem: targetView, attribute: attribute, multiplier: multiplier, constant: constant)
4141
constraints.bottom?.isActive = true
4242
return self
4343
}
4444
@discardableResult
45-
public func center(by target: UIView? = nil, centerX: Bool = true, centerY: Bool = true, x: CGFloat = 0, y: CGFloat = 0) -> SimpleLayoutObject {
45+
public func center(by target: Any? = nil, centerX: Bool = true, centerY: Bool = true, x: CGFloat = 0, y: CGFloat = 0) -> SimpleLayoutObject {
4646
if centerX {
4747
self.centerX(by: target, x)
4848
}
@@ -52,28 +52,28 @@ public class SimpleLayoutObject: NSObject {
5252
return self
5353
}
5454
@discardableResult
55-
public func centerX(by target: UIView? = nil, multiplier: CGFloat = 1.0, _ constant: CGFloat = 0) -> SimpleLayoutObject {
55+
public func centerX(by target: Any? = nil, multiplier: CGFloat = 1.0, _ constant: CGFloat = 0) -> SimpleLayoutObject {
5656
removeHorizontalConstraints()
5757

58-
let targetView = target != nil ? target! : view.superview
58+
let targetView = target != nil ? target! : view.superview as Any
5959
constraints.centerX = NSLayoutConstraint(item: view, attribute: .centerX, relatedBy: .equal, toItem: targetView, attribute: .centerX, multiplier: multiplier, constant: constant)
6060
constraints.centerX?.isActive = true
6161
return self
6262
}
6363
@discardableResult
64-
public func centerY(by target: UIView? = nil, multiplier: CGFloat = 1.0, _ constant: CGFloat = 0) -> SimpleLayoutObject {
64+
public func centerY(by target: Any? = nil, multiplier: CGFloat = 1.0, _ constant: CGFloat = 0) -> SimpleLayoutObject {
6565
removeVerticalConstraints()
6666

67-
let targetView = target != nil ? target! : view.superview
67+
let targetView = target != nil ? target! : view.superview as Any
6868
constraints.centerY = NSLayoutConstraint(item: view, attribute: .centerY, relatedBy: .equal, toItem: targetView, attribute: .centerY, multiplier: multiplier, constant: constant)
6969
constraints.centerY?.isActive = true
7070
return self
7171
}
7272
@discardableResult
73-
public func trailing(by target: UIView? = nil, attribute: NSLayoutAttribute = .trailing, relation: NSLayoutRelation = .equal, multiplier: CGFloat = 1.0, _ constant: CGFloat = 0) -> SimpleLayoutObject {
73+
public func trailing(by target: Any? = nil, attribute: NSLayoutAttribute = .trailing, relation: NSLayoutRelation = .equal, multiplier: CGFloat = 1.0, _ constant: CGFloat = 0) -> SimpleLayoutObject {
7474
removeTrailing()
7575

76-
let targetView = target != nil ? target! : view.superview
76+
let targetView = target != nil ? target! : view.superview as Any
7777
constraints.trailing = NSLayoutConstraint(item: view, attribute: .trailing, relatedBy: relation, toItem: targetView, attribute: attribute, multiplier: multiplier, constant: constant)
7878
constraints.trailing?.isActive = true
7979
return self
@@ -97,13 +97,13 @@ public class SimpleLayoutObject: NSObject {
9797
return self
9898
}
9999
@discardableResult
100-
public func height(by target: UIView? = nil, fixed: CGFloat = -1, relation: NSLayoutRelation = .equal, attribute: NSLayoutAttribute = .height, multiplier: CGFloat = 1.0, _ constant: CGFloat = 0) -> SimpleLayoutObject {
100+
public func height(by target: Any? = nil, fixed: CGFloat = -1, relation: NSLayoutRelation = .equal, attribute: NSLayoutAttribute = .height, multiplier: CGFloat = 1.0, _ constant: CGFloat = 0) -> SimpleLayoutObject {
101101
if let height = constraints.height {
102102
view.removeConstraint(height)
103103
view.superview?.removeConstraint(height)
104104
}
105105

106-
let targetView = target != nil ? target! : view.superview
106+
let targetView = target != nil ? target! : view.superview as Any
107107
if fixed > -1 {
108108
constraints.height = NSLayoutConstraint(item: view, attribute: .height, relatedBy: relation, toItem: nil, attribute: .notAnAttribute, multiplier: multiplier, constant: fixed)
109109
} else {
@@ -113,31 +113,31 @@ public class SimpleLayoutObject: NSObject {
113113
return self
114114
}
115115
@discardableResult
116-
public func leading(by target: UIView? = nil, attribute: NSLayoutAttribute = .leading, relation: NSLayoutRelation = .equal, multiplier: CGFloat = 1.0, _ constant: CGFloat = 0) -> SimpleLayoutObject {
116+
public func leading(by target: Any? = nil, attribute: NSLayoutAttribute = .leading, relation: NSLayoutRelation = .equal, multiplier: CGFloat = 1.0, _ constant: CGFloat = 0) -> SimpleLayoutObject {
117117
removeLeading()
118118

119-
let targetView = target != nil ? target! : view.superview
119+
let targetView = target != nil ? target! : view.superview as Any
120120
constraints.leading = NSLayoutConstraint(item: view, attribute: .leading, relatedBy: relation, toItem: targetView, attribute: attribute, multiplier: multiplier, constant: constant)
121121
constraints.leading?.isActive = true
122122
return self
123123
}
124124
@discardableResult
125-
public func top(by target: UIView? = nil, attribute: NSLayoutAttribute = .top, multiplier: CGFloat = 1.0, _ constant: CGFloat = 0) -> SimpleLayoutObject {
125+
public func top(by target: Any? = nil, attribute: NSLayoutAttribute = .top, multiplier: CGFloat = 1.0, _ constant: CGFloat = 0) -> SimpleLayoutObject {
126126
removeTop()
127127

128-
let targetView = target != nil ? target! : view.superview
128+
let targetView = target != nil ? target! : view.superview as Any
129129
constraints.top = NSLayoutConstraint(item: view, attribute: .top, relatedBy: .equal, toItem: targetView, attribute: attribute, multiplier: multiplier, constant: constant)
130130
constraints.top?.isActive = true
131131
return self
132132
}
133133
@discardableResult
134-
public func width(by target: UIView? = nil, fixed: CGFloat = -1, relation: NSLayoutRelation = .equal, attribute: NSLayoutAttribute = .width, multiplier: CGFloat = 1.0, _ constant: CGFloat = 0) -> SimpleLayoutObject {
134+
public func width(by target: Any? = nil, fixed: CGFloat = -1, relation: NSLayoutRelation = .equal, attribute: NSLayoutAttribute = .width, multiplier: CGFloat = 1.0, _ constant: CGFloat = 0) -> SimpleLayoutObject {
135135
if let width = constraints.width {
136136
view.removeConstraint(width)
137137
view.superview?.removeConstraint(width)
138138
}
139139

140-
let targetView = target != nil ? target! : view.superview
140+
let targetView = target != nil ? target! : view.superview as Any
141141
if fixed > -1 {
142142
constraints.width = NSLayoutConstraint(item: view, attribute: .width, relatedBy: relation, toItem: nil, attribute: .notAnAttribute, multiplier: multiplier, constant: fixed)
143143
} else {
@@ -235,13 +235,13 @@ public struct NSLayoutConstraints {
235235
public var centerY: NSLayoutConstraint?
236236

237237
public init(leading: NSLayoutConstraint? = nil,
238-
top: NSLayoutConstraint? = nil,
239-
trailing: NSLayoutConstraint? = nil,
240-
bottom: NSLayoutConstraint? = nil,
241-
height: NSLayoutConstraint? = nil,
242-
width: NSLayoutConstraint? = nil,
243-
centerX: NSLayoutConstraint? = nil,
244-
centerY: NSLayoutConstraint? = nil) {
238+
top: NSLayoutConstraint? = nil,
239+
trailing: NSLayoutConstraint? = nil,
240+
bottom: NSLayoutConstraint? = nil,
241+
height: NSLayoutConstraint? = nil,
242+
width: NSLayoutConstraint? = nil,
243+
centerX: NSLayoutConstraint? = nil,
244+
centerY: NSLayoutConstraint? = nil) {
245245
self.leading = leading
246246
self.top = top
247247
self.trailing = trailing

0 commit comments

Comments
 (0)