-
Notifications
You must be signed in to change notification settings - Fork 563
Closed
Milestone
Description
I would suggest the following additional init in LinearGradient.swift:
/// Inits a LinearGradient with a degree (optional) and with multiple Stops
///
/// - Parameters:
/// - degree: (optional) If 0, the Gradient is drawn from the left to the right. 90 is from top to bottom
/// - stops: An array of Stop (Stop has two properties: offset as Double (between 0 and 1.0) and color as Color)
public init(degree: Double = 0, stops: [Stop]) {
self.x1 = degree >= 135 && degree < 270 ? 1 : 0
self.y1 = degree < 225 ? 0 : 1
self.x2 = degree < 90 || degree >= 315 ? 1 : 0
self.y2 = degree >= 45 && degree < 180 ? 1 : 0
super.init(
userSpace: false,
stops: stops
)
}
Then you can use something like:
LinearGradient(degree: 270, stops: [Stop(offset: 0, color: Color(val: 0x123123)), Stop(offset: 0.4, color: Color(val: 0x123456))])