iOS渐变色startPoint和endPoint

UIView *gradientView = [[UIView alloc] initWithFrame:CGRectMake(0, 45 * kHeightRatio, bgView.width, 3)];

[bgView addSubview:gradientView];

    

CAGradientLayer *gradient = [CAGradientLayer layer];

gradient.frame = gradientView.bounds;

gradient.colors = [NSArray arrayWithObjects:

                   (id)[UIColor colorWithRed:51 / 255.0 green:193/255.0 blue:188/255.0 alpha:1.0].CGColor,

                   (id)[UIColor colorWithRed:34 / 255.0 green:201/255.0 blue:161/255.0 alpha:1.0].CGColor,

                   (id)[UIColor colorWithRed:65 / 255.0 green:1 blue:234/255.0 alpha:1.0].CGColor, nil];

gradient.startPoint = CGPointMake(0, 0.5);

gradient.endPoint = CGPointMake(1, 0.5);

gradient.locations = @[@0,@0.4,@1];

[gradientView.layer addSublayer:gradient];

//startPoint和endPoint范围在0到1之间

左上角的,右上角,左下角,右下角的坐标分别为(0,1),(1,1),(0,0),(1,0)

你可能感兴趣的:(iOS渐变色startPoint和endPoint)