Created
June 5, 2020 13:14
-
-
Save boyvanamstel/e01e689dd141d3d97d202007e9bacd2d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSDirectionalEdgeInsets { | |
/// Returns new insets with just a value applied to the supplied edge. | |
/// | |
/// - Parameters: | |
/// - edge: The edge to apply an inset to. | |
/// - value: The value to set the edge inset to. | |
init(_ edge: WritableKeyPath<Self, CGFloat>, _ value: CGFloat) { | |
self.init( | |
top: edge == \.top ? value : 0.0, | |
leading: edge == \.leading ? value: 0.0, | |
bottom: edge == \.bottom ? value : 0.0, | |
trailing: edge == \.trailing ? value : 0.0 | |
) | |
} | |
} | |
let bottomInsets = NSDirectionalEdgeInsets(\.bottom, 200.0) | |
print(bottomInsets) // NSDirectionalEdgeInsets(top: 0.0, leading: 0.0, bottom: 200.0, trailing: 0.0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment