下面的代码绘制了一个完美的椭圆径向渐变,但没有填充它的视图的角落。如何让它超出椭圆的边缘?记录的选项是 kCGGradientDrawsAfterEndLocation,但我认为它在 ios 中不可用。
- (void)drawRect:(CGRect)rect
{
CGFloat colors [] = {
0.2, 0.2, 0.2, 1.0,
0.0, 0.0, 0.0, 1.0
};
CGColorSpaceRef baseSpace = CGColorSpaceCreateDeviceRGB();
CGGradientRef gradient = CGGradientCreateWithColorComponents(baseSpace, colors, NULL, 2);
CGColorSpaceRelease(baseSpace), baseSpace = NULL;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextAddEllipseInRect(context, rect);
CGContextClip(context);
CGContextDrawRadialGradient(context, gradient, self.center, 0, self.center, self.frame.size.width, kCGGradientDrawsAfterEndLocation);
CGGradientRelease(gradient), gradient = NULL;
CGContextRestoreGState(context);
}