let view = UIView(frame: .init(x: 10, y: 100, width: 200, height: 100))
self.view.addSubview(view)
let gradientLayer = CAGradientLayer()
gradientLayer.frame = view.frame
gradientLayer.colors = [UIColor.red.cgColor,UIColor.yellow.cgColor]
gradientLayer.locations = [0.1,0.4]
gradientLayer.startPoint = CGPoint(x: 0, y: 0)
gradientLayer.endPoint = CGPoint(x: 1, y: 1)
view.layer.addSublayer(gradientLayer)
网友评论