iOS View渐变色

    UIView *view = [[UIView alloc] init];
    view.frame = CGRectMake(0,0,SCREEN_WIDTH,222);
    [self.view addSubview:view];
    // gradient
    CAGradientLayer *gl = [CAGradientLayer layer];
    gl.frame = CGRectMake(0,0,SCREEN_WIDTH,222);
    gl.startPoint = CGPointMake(0.65, 0);//渐变色起始点
    gl.endPoint = CGPointMake(0.18, 1);//渐变色结束点
    gl.colors = @[(__bridge id)[UIColor colorWithRed:39/255.0 green:140/255.0 blue:248/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:62/255.0 green:110/255.0 blue:213/255.0 alpha:1.0].CGColor];//这里可以是多个颜色的array
    gl.locations = @[@(0), @(1.0f)];//渐变色节点位置
    [view.layer addSublayer:gl];

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