iOS渐变色

fileprivate func setupColor(view: UIView) {

let gradientLayer = CAGradientLayer()

//设置渐变的主颜色

gradientLayer.colors = [colorConversion(Color_Value: "44d3ba", alpha: 1.0).cgColor, Common.mainColor.cgColor]

// gradientLayer.locations = [0.0,0.7] 颜色所占区域

//设置渲染的起始结束位置(横向渐变,竖向渐变不需要下边两个属性)

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

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

gradientLayer.frame = CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height)

//将gradientLayer作为子layer添加到主layer上

view.layer.insertSublayer(gradientLayer, at: 0)

} http://www.hangge.com/blog/cache/detail_1772.html

你可能感兴趣的:(iOS渐变色)