Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LinearGradient: Init with stops #238

Closed
JoachimM7 opened this issue Dec 2, 2017 · 1 comment
Closed

LinearGradient: Init with stops #238

JoachimM7 opened this issue Dec 2, 2017 · 1 comment
Assignees
Milestone

Comments

@JoachimM7
Copy link
Contributor

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))])

@ystrot ystrot self-assigned this Dec 4, 2017
@ystrot ystrot added this to the 0.9.2 milestone Dec 4, 2017
@ystrot ystrot closed this as completed in c82404f Dec 13, 2017
@ystrot
Copy link
Member

ystrot commented Dec 13, 2017

This fix available in master version and will be part of 0.9.2 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants