CAGradientLayer是CALayer的一个子类,用来生成渐变色的Layer。
CAGradientLayer有5个属性:
@property(nullable, copy) NSArray *colors; // CGColorRef数组,用来定义渐变节点颜色
@property(nullable, copy) NSArray<NSNumber *> *locations; // 存储每个渐变节点位置
@property CGPoint startPoint; // 渐变色的起始点
@property CGPoint endPoint; // 渐变色的结束点,和起始点共同能够成渐变方向
@property(copy) NSString *type; // 没什么意义,只能设置为axial
CAGradientLayer的具体使用方法如下:
CAGradientLayer *caL = [CAGradientLayer layer];
caL.frame = CGRectMake(0,0,SCREEN_WIDTH,170);
caL.startPoint = C GPointMake(0, 0);
caL.endPoint = CGPointMake(1, 1);
caL.colors = @[(__bridge id)[UIColor colorWithRed:255/255.0 green:128/255.0 blue:58/255.0 alpha:1.0].CGColor,(__bridge id)[UIColor colorWithRed:255/255.0 green:86/255.0 blue:12/255.0 alpha:1.0].CGColor]; caL.locations = @[@(0.0),@(1.0f)];
[self.navigationBgView.layer addSublayer:caL];
网友评论