码迷,mamicode.com
首页 > 其他好文 > 详细

CAGradientLayer渐变效果

时间:2016-09-10 20:33:21      阅读:332      评论:0      收藏:0      [点我收藏+]

标签:

属性

  1. startPointendPoint
    决定渐变方向,以单位坐标系定义。左上角{0,0},右下角{1,1}
  2. colors
    渐变的颜色,是一个CGColorRef的数组。
  3. locations
    定义了渲染的每个颜色的位置。取值在0到1之间。长度一定和colors相同。

例子

  1. 多重渐变

        var gradientLayer = CAGradientLayer.init()
        gradientLayer.colors = [UIColor.init(red: 0, green: 0, blue: 0, alpha: 0.6).CGColor,UIColor.init(red: 0, green: 0, blue: 0, alpha: 0.9).CGColor,UIColor.init(white: 0.4, alpha: 0.5).CGColor]
        gradientLayer.colors = [UIColor.blackColor().CGColor,UIColor.yellowColor().CGColor,UIColor.blueColor().CGColor]
        gradientLayer.locations = [0.1,0.3,0.5]
        gradientLayer.frame = textLayer.bounds
        gradientLayer.startPoint = CGPointMake(1, 0)
        gradientLayer.endPoint = CGPointMake(1, 1)
    //        textLayer.mask = gradientLayer
        self.contentView.layer.addSublayer(gradientLayer)     
    

    技术分享?

  2. 作为蒙版,实现文字渐变

        var gradientLayer = CAGradientLayer.init()
        gradientLayer.colors = [UIColor.init(red: 0, green: 0, blue: 0, alpha: 0.6).CGColor,UIColor.init(red: 0, green: 0, blue: 0, alpha: 0.9).CGColor,UIColor.init(white: 0.4, alpha: 0.5).CGColor]
    //        gradientLayer.colors = [UIColor.blackColor().CGColor,UIColor.yellowColor().CGColor,UIColor.blueColor().CGColor]
        gradientLayer.locations = [0.1,0.3,0.5]
        gradientLayer.frame = textLayer.bounds
        gradientLayer.startPoint = CGPointMake(1, 0)
        gradientLayer.endPoint = CGPointMake(1, 1)
        textLayer.mask = gradientLayer
    

    技术分享?

CAGradientLayer渐变效果

标签:

原文地址:http://www.cnblogs.com/huahuahu/p/CAGradientLayer-jian-bian-xiao-guo.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!