IOS图层Layer学习笔记(七)—— CAGradientLayer

简介

CAGradientLayer是的CALayer的子类,能够让颜色渐变填充。
填充的颜色是在backgroundColor 上面,子图层下面。

属性

colors

NSArray*, Animatable。渐变色数组,颜色必须是CGColorRef类型。默认nil。

// 光带效果
UIColor *lucencyColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.2];
UIColor *opaqueColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
_subLayer.colors = @[(__bridge id _Nullable)opaqueColor.CGColor,
                     (__bridge id _Nullable)lucencyColor.CGColor,
                     (__bridge id _Nullable)opaqueColor.CGColor];
_subLayer.locations = @[@(0.3), @(0.5), @(0.7)];

colors

locations

NSArray< NSNumber* >*, Animatable。与colors对应的颜色分割位置。默认nil。
如果locations为nil,则colors的值在[0.0, 1.0]之间等分。
如果locations.count小于colors.count,则只能显示比locations.count多1个colors成员,并且最后一个colors是在1.0位置。
如果locations.count大于colors.count,则locations多余的位置全部显示colors的最后一个成员。

成员数值有效范围为[0.0, 1.0],并且数组的值必须是递增的。具体位置需要根据startPointendPoint来判断。
虽然数组有效范围是[0.0, 1.0],但小于0.0和大于1.0的数值范围还是有一定作用的,比如某些动画效果:

// 一条光带不停的来回移动
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"locations"];
animation.fromValue = @[@(-0.4), @(-0.2), @(-0.01)];
animation.toValue = @[@(1.0), @(1.2), @(1.4)];
animation.duration = 1.0;
animation.autoreverses = YES;
animation.repeatCount = FLT_MAX;
[_subLayer addAnimation:animation forKey:nil];

movePoint

startPoint

CGPoint, Animatable。层渐变绘制控制线起点。计算值。默认(0.5, 0.0).

endPoint

CGPoint, Animatable。层渐变绘制控制线起点。计算值。默认(0.5, 1.0).

type

NSString *,No Animatable。渐变样式。只有一个可选值。

NSString * const kCAGradientLayerAxial;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值