-1

I have this code to modify the colors from the interface :

@IBDesignable
class GradientView: UIView {
    @IBInspectable var firstColor: UIColor = UIColor.clear{
        didSet{
            updateView()
        }
    }

    @IBInspectable var secondColor: UIColor = UIColor.clear{
        didSet{
            updateView()
        }
    }

    override class var layerClass: AnyClass{
        get{
            return CAGradientLayer.self
        }
    }

    func updateView(){
        let layer = self.layer as! CAGradientLayer
        layer.colors = [ firstColor.cgColor, secondColor.cgColor ]
        layer.locations = [ 0.5 ]
    }
}

How can I add here to modify the angle?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Fulano
  • 71
  • 8

1 Answers1

0

You can use the properties endPoint and startPoint of your CAGradientLayer. Like so:

let x: Double! = angle / 360.0
let a = pow(sinf(Float(2.0 * .pi * ((x + 0.75) / 2.0))),2.0);
let b = pow(sinf(Float(2 * .pi * ((x+0.0)/2))),2);
let c = pow(sinf(Float(2 * .pi * ((x+0.25)/2))),2);
let d = pow(sinf(Float(2 * .pi * ((x+0.5)/2))),2);

I hope this helps!

Glenn Posadas
  • 12,555
  • 6
  • 54
  • 95