swift3.0 渐变色

前端之家收集整理的这篇文章主要介绍了swift3.0 渐变色前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
class ViewController: UIViewController {
    
    private var gradientLayer:CAGradientLayer = CAGradientLayer()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.gradientLayer.frame = self.view.bounds
        
        self.gradientLayer.colors = [UIColor .clear.cgColor,UIColor.black.cgColor]
        
        self.gradientLayer.opacity = 1
        
        gradientLayer.locations = [0,1]
        
        gradientLayer.startPoint = CGPoint(x: 0,y: 0.5)
        
        gradientLayer.endPoint = CGPoint(x: 1,y: 0.5)
        
        view.layer.addSublayer(self.gradientLayer)
        
    }
    
    
    
}
var gradientLayer2 = CAGradientLayer()
        gradientLayer2.startPoint = CGPointMake(0.5,1.0)
        gradientLayer2.endPoint = CGPointMake(0.5,0.0)
        gradientLayer2.frame = CGRectMake(0,bounds.size.width,bounds.size.height)
        gradientLayer2.colors = [UIColor.yellowColor().CGColor,UIColor.blueColor().CGColor,UIColor.greenColor().CGColor]
        self.view.layer.addSublayer(gradientLayer2)
原文链接:https://www.f2er.com/swift/322613.html

猜你在找的Swift相关文章