Skip to content

How to pass the gradient colors as a variable #1

@alamodey

Description

@alamodey

Hi,

I am trying to incorporate this code into my project and I am having trouble changing the colors so that it's not always grey and orange. Is it possible to edit this code anywhere so it'll accept variables for the colors:

//MARK: Private Methods
   private lazy var gradient: CAGradientLayer = {
       let gradientLayer = CAGradientLayer()
       gradientLayer.colors = [UIColor.darkGray.cgColor, UIColor.orange.cgColor]
       gradientLayer.startPoint = CGPoint(x: 0, y: 0)
       gradientLayer.endPoint = CGPoint(x: 1, y: 1)
       gradientLayer.frame = self.bounds
       return gradientLayer
   }()

How do I call this from my controller with variable colors?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions