/// 渐变色
lazy var gradLayer: CAGradientLayer = { // 渐变色 let g = CAGradientLayer() g.colors = [UIColor.rgba(14, 21, 57, 0).cgColor,UIColor.rgba(14, 21, 57, 0.5).cgColor,UIColor.rgba(14, 21, 57, 0.5).cgColor,UIColor.rgba(6, 8, 22, 0).cgColor,UIColor.rgba(14, 21, 57, 0).cgColor] //渐变颜色
g.locations = [0.2,0.5,0.8];//渐变起始位置
g.startPoint = CGPoint.init(x: 0, y: 0)
g.endPoint = CGPoint.init(x: 1, y: 0) return g }()
self.mainView.layer.addSublayer(gradLayer) DispatchQueue.main.asyncAfter(deadline: .now()) { // self.gradLayer.frame = self.mainView.bounds }