Created
April 2, 2023 09:16
-
-
Save HarshilShah/e042587358d9391ae9713a4651970020 to your computer and use it in GitHub Desktop.
Convenient initialisers for SwiftUI's LinearGradient view
This file contains hidden or 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
import SwiftUI | |
public extension UnitPoint { | |
var diametricallyOpposite: UnitPoint { | |
UnitPoint(x: 1 - x, y: 1 - y) | |
} | |
} | |
public extension LinearGradient { | |
init(colors: [Color], towards end: UnitPoint) { | |
self.init(colors: colors, startPoint: end.diametricallyOpposite, endPoint: end) | |
} | |
init(gradient: Gradient, towards end: UnitPoint) { | |
self.init(gradient: gradient, startPoint: end.diametricallyOpposite, endPoint: end) | |
} | |
init(stops: [Gradient.Stop], towards end: UnitPoint) { | |
self.init(stops: stops, startPoint: end.diametricallyOpposite, endPoint: end) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment