您的位置:首页 > 运维架构

CAGradientLayer简介

2012-05-04 13:05 274 查看
CAGradientLayer可以方便的处理颜色渐变。

Properties:
@property(copy) NSArray *colors
渐变颜色的数组

[cpp] view
plaincopy

[NSArray arrayWithObjects:(id)[[[UIColor blackColor] colorWithAlphaComponent:1] CGColor],  

                          (id)[[[UIColor yellowColor] colorWithAlphaComponent:1] CGColor],  

                          (id)[[[UIColor blueColor] colorWithAlphaComponent:1] CGColor],  

                  (id)[[UIColor clearColor] CGColor],  

              nil];  

如上定义了四种颜色(最后一种是无色)。

@property(copy) NSArray *locations
渐变颜色的区间分布,locations的数组长度和color一致,这个值一般不用管它,默认是nil,会平均分布。

[cpp] view
plaincopy

[NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0],  

                          [NSNumber numberWithFloat:0.3],  

                          [NSNumber numberWithFloat:0.8],  

                          [NSNumber numberWithFloat:1.0],  

                          nil];  

注意这几个数字在0到1之间单调递增。

@property CGPoint startPoint
映射locations中第一个位置,用单位向量表示,比如(0,0)表示从左上角开始变化。默认值是(0.5,0.0)。

@property CGPoint endPoint
映射locations中最后一个位置,用单位向量表示,比如(1,1)表示到右下角变化结束。默认值是(0.5,1.0)。

@property(copy) NSString *type
默认值是kCAGradientLayerAxial,表示按像素均匀变化。除了默认值也无其它选项。

下面是我用上面的代码实现的最终效果,startPoint是(0,0),endPoint是(1,1)。

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