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

Repeating gradient #548

Open
phimage opened this issue Mar 30, 2018 · 2 comments
Open

Repeating gradient #548

phimage opened this issue Mar 30, 2018 · 2 comments

Comments

@phimage
Copy link
Member

phimage commented Mar 30, 2018

We could add easily repeating gradient

We can find the concept in css
https://www.w3schools.com/cssref/tryit.asp?filename=trycss3_gradient-linear_repeating2
https://developer.apple.com/library/content/documentation/InternetWeb/Conceptual/SafariVisualEffectsProgGuide/Gradients/Gradient.html

We need for that the number of repetitions
We could add parameter to the GradientMode or I prefer to add a var in GradientDesignable

For Linear it is very easy

let layer = CAGradientLayer()
layer.colors = colors.aFunctionToDuplicate(numberOfRepeat: 5) 

screen shot 2018-03-30 at 14 40 27

For radial, same things and also an adaptation must be done when computing locations (now it is [0, 1])
I try with that but not sure that we must do that

var locations: [CGFloat] = []
    let size: CGFloat = 1 / CGFloat(colors.count)
    var pos: CGFloat = 0
    for _ in 0..<colors.count {
      locations.append( pos)
      pos += size
    }
    locations.append(1)

screen shot 2018-03-30 at 14 54 51

@JakeLin
Copy link
Member

JakeLin commented Apr 3, 2018

TIL, great idea. I prefer to add an associated value to the enum since we provide similar API for Animtable and some other properties. But we need to handle the parsing careful to apply default 1 to not break the existing @IBInspectable var _gradientMode: String?.

@tbaranes any idea on the API interface?

@phimage
Copy link
Member Author

phimage commented May 21, 2018

New idea, when repeating have an odd numbers of colors, with last colors same as first colors
See #567 for smooth conic gradient

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

No branches or pull requests

2 participants