Friday 29 June 2018

Create Gradient in View With locations from zeplin

I am working on a project where i need to apply gradients to the view. I am having sketch file and have colors which i am going to use for gradient with the locations but i am unable to get the exact view.

Can anyone please help how to get that?

I have created a function to apply gradient:-

func applyGradient(colours: [UIColor]) -> Void {
        let gradient: CAGradientLayer = CAGradientLayer()
        gradient.frame = self.bounds
        gradient.colors = colours.map { $0.cgColor }
        self.layer.insertSublayer(gradient, at: 0)
    }

func applyGradientToView(){
        let firstColor = UIColor(red: 26/255, green: 169/255, blue: 186/255, alpha: 1.0)
        let secondColor = UIColor(red: 26/255, green: 97/255, blue: 157/255, alpha: 1.0)
        let thirdColor = UIColor(red: 27/255, green: 65/255, blue: 144/255, alpha: 1.0)
        self.applyGradient(colours: [firstColor, secondColor, thirdColor])
    }

Here array UIcolor is a combination of colors to be used, I used all three but still, I didn't get the same as in the sketch

What I created :-

enter image description here

Gradient colors in sketch file:-

enter image description here

The view in sketch file is like this:-

enter image description here



from Create Gradient in View With locations from zeplin

No comments:

Post a Comment