Skip to content

Commit 03934af

Browse files
committed
Added setEqualSuperviewMarginsWithAutoLayout.
1 parent 8b0f9a9 commit 03934af

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Sources/SparrowKit/UIKit/Extensions/UIViewExtension.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,23 @@ public extension UIView {
221221
])
222222
}
223223

224+
/**
225+
SparrowKit: Set view equal frame to superview frame exlude margins via Auto Layout.
226+
227+
- warning:
228+
If view not have superview, constraints will not be added.
229+
*/
230+
func setEqualSuperviewMarginsWithAutoLayout() {
231+
guard let superview = self.superview else { return }
232+
translatesAutoresizingMaskIntoConstraints = false
233+
NSLayoutConstraint.activate([
234+
topAnchor.constraint(equalTo: superview.layoutMarginsGuide.topAnchor),
235+
leftAnchor.constraint(equalTo: superview.layoutMarginsGuide.leftAnchor),
236+
rightAnchor.constraint(equalTo: superview.layoutMarginsGuide.rightAnchor),
237+
bottomAnchor.constraint(equalTo: superview.layoutMarginsGuide.bottomAnchor)
238+
])
239+
}
240+
224241
// MARK: - Appearance
225242

226243
/**

0 commit comments

Comments
 (0)