iOS颜色渐变效果 CAGradientLayer

1、继承关系

截屏2020-12-13 下午7.48.15.png

2、CAGradientLayer

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];

    CAGradientLayer *graLayer = [CAGradientLayer layer];
    graLayer.frame = CGRectMake(100, 100, 200, 200);
    graLayer.colors = @[
        (__bridge id)[UIColor redColor].CGColor,
        (__bridge id)[UIColor yellowColor].CGColor
    ];
//    graLayer.locations = @[@0, @0.2];
    graLayer.startPoint = CGPointMake(0, 0);
    graLayer.endPoint = CGPointMake(1, 1);
    [self.view.layer addSublayer:graLayer];
}
截屏2020-12-13 下午7.50.07.png

推荐阅读更多精彩内容