渐变色
2018-03-13 本文已影响6人
_Jock羁
渐变色
- (void)viewDidLoad {
[super viewDidLoad];
_contentView = [UIView new];
_contentView.frame = CGRectMake(100, 100, 100, 100);
_contentView.backgroundColor = [UIColor redColor];
[self.view addSubview:_contentView];
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = self.contentView.bounds;
[self.contentView.layer addSublayer:gradientLayer];
// gradientLayer.colors = (__bridge NSArray * _Nullable)([UIColor blueColor].CGColor);
// gradientLayer.colors = (__bridge NSArray * _Nullable)([UIColor cyanColor].CGColor);
//渐变区域
gradientLayer.locations = @[[NSNumber numberWithFloat:0.3], [NSNumber numberWithFloat:0.8]];
gradientLayer.colors = @[(__bridge NSArray * _Nullable)([UIColor blueColor].CGColor), (__bridge NSArray * _Nullable)([UIColor redColor].CGColor)];
// gradientLayer.startPoint = CGPointMake(0, 0);
//最大值为 (1, 1),最小值为(0, 0)
gradientLayer.startPoint = CGPointMake(1, 0);
gradientLayer.endPoint = CGPointMake(1, 1);
}