天天看點

swift 設定漸變背景顔色

let layer = CAGradientLayer()

layer.frame = view.bounds

///設定顔色

layer.colors = [color("61ccc8").cgColor,color("61ccc8").cgColor,kRGBColorAlpha(r: 97, g: 204, b: 200, alpha: 0.1).cgColor]

///設定顔色漸變的位置 (我這裡是橫向 中間點開始變化)

layer.locations = [0,0.5,1]

///開始的坐标點

layer.startPoint = CGPoint(x: 0, y: 0)

///結束的坐标點

layer.endPoint = CGPoint(x: 1, y: 0)

view.layer.addSublayer(layer)