- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGFloat locations[] = {0.0, 1.0};
// 蓝色
// NSArray* colors = [NSArray arrayWithObjects:(__bridge id)RGBCOLOR(4, 135, 243).CGColor, (__bridge id)RGBCOLOR(1, 94, 230).CGColor, nil];
// 黄色
NSArray* colors = [NSArray arrayWithObjects:(__bridge id)RGBCOLOR(243, 145, 4).CGColor, (__bridge id)RGBCOLOR(230, 103, 1).CGColor, nil];
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)colors, locations);
CGPoint startPoint = CGPointMake(CGRectGetWidth(rect) / 2, 0);
CGPoint endPoint = CGPointMake(CGRectGetWidth(rect) / 2, CGRectGetHeight(rect));
CGContextSaveGState(context);
CGContextAddRect(context, rect);
CGContextClip(context);
CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
CGContextRestoreGState(context);
CGGradientRelease(gradient);
CGColorSpaceRelease(colorSpace);
}