您的位置:首页 > 移动开发 > Swift

实现透明度渐变和颜色渐变

2015-06-12 16:15 405 查看
 //Transparent Gradient Layer
   
func insertTransparentGradient(#frame:
CGRect) {

        
       
let colorOne = UIColor(red:
100/255, green:
100/255, blue:
100/255, alpha:
0)
       
let colorTwo = UIColor(red:
100/255, green:
100/255, blue:
100/255, alpha:
1)

        
       
let colors = [colorOne.CGColor, colorTwo.CGColor]
       
let stopOne = 0.0
       
let stopTwo = 1.0
       
let locations = [stopOne, stopTwo]

        
       
let headerLayer =
CAGradientLayer()
        headerLayer.colors = colors
        headerLayer.locations = locations
        headerLayer.frame = frame
       
self.layer.insertSublayer(headerLayer, atIndex:
0)
    }

    

    //color gradient layer
   
func insertColorGradient(#frame:
CGRect) {

        
       
let colorOne = UIColor(red:
255/255, green:
255/255, blue:
255/255, alpha:
1)
       
let colorTwo = UIColor(red:
33/255, green:
33/255, blue:
33/255, alpha:
1)

        
       
let colors = [colorOne.CGColor, colorTwo.CGColor]
       
let stopOne = 0.0
       
let stopTwo = 1.0
       
let locations = [stopOne, stopTwo]

        
       
let headerLayer =
CAGradientLayer()
        headerLayer.c
b94a
olors = colors
        headerLayer.locations = locations
        headerLayer.frame = frame
       
self.layer.insertSublayer(headerLayer, above:
nil)

    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  CALayer IOS swift color