iOS 实现渐变色

1。 

#import

CAGradientLayer *gradient = [CAGradientLayer layer];

gradient.frame = rect;

gradient.colors = [NSArray arrayWithObjects:(id)[UIColor redColor].CGColor, 

                                            (id)[UIColor yellowColor].CGColor, 

                                            (id)[UIColor greenColor].CGColor,nil];

[self.layer insertSublayer:gradient atIndex:0];



2。

            CGRect barRect=CGRectMake(xPosition, self.bounds.size.height - 180 - 13, 30, 180);

            CGColorRef upColor = [UIColor colorWithRed:254/255.0 green:186/255.0 blue:187/255.0 alpha:1.0].CGColor;

            CGColorRef downColor = [UIColor colorWithRed:255/255.0 green:91/255.0 blue:92/255.0 alpha:1.0].CGColor;

            drawLinearGradient(context, barRect, upColor, downColor);



你可能感兴趣的:(iOS)