Skip to content

Commit

Permalink
Merge pull request #32 from allaboutapps/feature/ConvenienceInitInsets
Browse files Browse the repository at this point in the history
added convenience inits to NSDirectionalEdgeInsets and UIEdgeInsets
  • Loading branch information
mpoimer authored Sep 1, 2022
2 parents 76852f7 + 2638b37 commit 61b632d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
import UIKit

public extension NSDirectionalEdgeInsets {
init(vertical: CGFloat, horizontal: CGFloat) {
init(vertical: CGFloat = .zero, horizontal: CGFloat = .zero) {
self.init(top: vertical, leading: horizontal, bottom: vertical, trailing: horizontal)
}

init(_ value: CGFloat) {
self.init(vertical: value, horizontal: value)
}

init(vertical: CGFloat) {
self.init(vertical: vertical, horizontal: .zero)
}

init(horizontal: CGFloat) {
self.init(vertical: .zero, horizontal: horizontal)
init(
leading: CGFloat = .zero,
top: CGFloat = .zero,
trailing: CGFloat = .zero,
bottom: CGFloat = .zero
) {
self.init(top: top, leading: leading, bottom: bottom, trailing: trailing)
}
}

Expand Down
24 changes: 24 additions & 0 deletions Sources/Toolbox/Extensions/UIKit/UIEdgeInsets+Convenience.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#if canImport(UIKit)

import UIKit

public extension UIEdgeInsets {
init(vertical: CGFloat = .zero, horizontal: CGFloat = .zero) {
self.init(top: vertical, left: horizontal, bottom: vertical, right: horizontal)
}

init(_ value: CGFloat) {
self.init(vertical: value, horizontal: value)
}

init(
left: CGFloat = .zero,
top: CGFloat = .zero,
right: CGFloat = .zero,
bottom: CGFloat = .zero
) {
self.init(top: top, left: left, bottom: bottom, right: right)
}
}

#endif

0 comments on commit 61b632d

Please sign in to comment.