class GradientView: UIView {
private var gradientLayer = CAGradientLayer()
private var vertical: Bool = false
func draw(_ colors: [Any]? , isVertical : Bool, locations: [NSNumber]? = [0.0, 1.0]) {
self.vertical = isVertical
gradientLayer.frame = self.bounds
if gradientLayer.superlayer == nil {
gradientLayer.startPoint = CGPoint(x: 0, y: 0)
gradientLayer.endPoint = vertical ? CGPoint(x: 0, y: 1) : CGPoint(x: 1, y: 0)
gradientLayer.colors = colors
gradientLayer.locations = locations
self.layer.insertSublayer(gradientLayer, at: 0)
}
}
}