IBAnimatable icon indicating copy to clipboard operation
IBAnimatable copied to clipboard

Repeating gradient

Open phimage opened this issue 7 years ago • 2 comments

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

phimage avatar Mar 30 '18 13:03 phimage

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?

JakeLin avatar Apr 03 '18 04:04 JakeLin

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

phimage avatar May 21 '18 08:05 phimage