CAGradientLayer使用——渐变色

2019-05-16  本文已影响0人  秋分落叶

UIView *colorView = [[UIView alloc] init];

colorView.frame = CGRectMake(0, 0, 200, 200);

colorView.center = CGPointMake(375/2.0, 667/2.0-100);

[self.view addSubview:colorView];

CAGradientLayer *gradient = [CAGradientLayer layer];

gradient.frame = colorView.bounds;

gradient.colors = @[(id)[UIColor blackColor].CGColor,(id)[UIColor whiteColor].CGColor];

gradient.startPoint = CGPointMake(0, 1);

gradient.endPoint = CGPointMake(1, 0);

gradient.locations = @[@(0.5f), @(1.0f)];

[colorView.layer addSublayer:gradient];

上一篇 下一篇

猜你喜欢

热点阅读