【发布时间】:2012-03-28 14:59:55
【问题描述】:
我有以下代码在 iOS5 上运行良好。
//// Abstracted Graphic Attributes
NSString* textContent = [NSString stringWithFormat:@"%i",[myAnnotation.annotations count]];
//// General Declarations
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = UIGraphicsGetCurrentContext();
//// Gradient Declarations
NSArray* gradient3Colors = [NSArray arrayWithObjects:
(id)[UIColor lightGrayColor].CGColor,
(id)[UIColor darkGrayColor].CGColor, nil];
CGFloat gradient3Locations[] = {0, 1};
CGGradientRef gradient3 = CGGradientCreateWithColors(colorSpace, (CFArrayRef)gradient3Colors, gradient3Locations);
//// Oval Drawing
UIBezierPath* ovalPath = [UIBezierPath bezierPathWithOvalInRect: CGRectMake(0.5, 0.5, 34, 34)];
CGContextSaveGState(context);
[ovalPath addClip];
CGContextDrawRadialGradient(context, gradient3,
CGPointMake(17.5, 17.5), 10,
CGPointMake(17.5, 17.5), 30,
kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);
CGContextRestoreGState(context);
[[UIColor blackColor] setStroke];
ovalPath.lineWidth = 0.5;
[ovalPath stroke];
//// Text Drawing
CGRect textFrame = CGRectMake(0, 7.0, 35, 20);
[[UIColor whiteColor] setFill];
[textContent drawInRect: textFrame withFont: [UIFont fontWithName: @"HelveticaNeue" size: [UIFont systemFontSize]] lineBreakMode: UILineBreakModeWordWrap alignment: UITextAlignmentCenter];
//// Cleanup
CGGradientRelease(gradient3);
CGColorSpaceRelease(colorSpace);
这会画一个灰色渐变的圆圈,中间是一个数字。在 iOS5 上,这显示正确。在 iOS4 上,它不会出错或提醒我使用错误的 API,除了绘制灰色渐变之外的所有内容!有什么想法吗?
【问题讨论】:
标签: ios core-graphics