iOS 渐变色View

通过 CAGradientLayer 实现
iOS 渐变色View_第1张图片

UIView * gradationView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 50)];
[self.view addSubview:gradationView];
    
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = gradationView.bounds;
// 渐变色颜色数组,可多个
gradientLayer.colors = [NSArray arrayWithObjects:(id)[[UIColor redColor] CGColor], (id)[[UIColor greenColor] CGColor], nil];
// 渐变的开始点 (不同的起始点可以实现不同位置的渐变,如图)
gradientLayer.startPoint = CGPointMake(0, 0.5f); //(0, 0)
// 渐变的结束点
gradientLayer.endPoint = CGPointMake(1, 0.5f); //(1, 1)
[gradationView.layer insertSublayer:gradientLayer atIndex:0];

你可能感兴趣的:(iOS 渐变色View)