1
我有以下代碼在iOS5上正常工作。CoreGraphics漸變不顯示在iOS4上
//// 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和一切,但灰色漸變已被繪製!任何想法呢?
我的猜測是這是一個ARC-on-ios4問題,如果您在創建數組之前將標準顏色分配給變量,那麼它也可以工作。 – jrturton 2012-03-29 08:29:16
我根本沒有使用ARC! – 2012-03-29 08:56:09
我也看到這個問題......黑色和灰色 – 2012-10-09 10:38:35