2014-02-17 51 views
2

I使用此函数绘制自定义UILabel。它适用于iOS 6及更早版本,但iOS 7失败。如果使用CGContextSetFillColorWithColor替换CGContextSetStrokeColorWithColor,则它适用于iOS7,但不适用于6及更早版本。CGContextSetStrokeColorWithColor失败,iOS 7

void ShadowedStrokedText(CGContextRef ctx,NSString *text,CGPoint textStartPont,UIColor *textColor,UIFont *font,CGFloat lineWidth,UIColor * shadowColor,CGFloat shadowThickness){ 

CGContextSaveGState(ctx); 

CGContextSetInterpolationQuality(ctx,kCGInterpolationHigh); 
CGContextSetLineJoin(ctx, kCGLineJoinRound); 

CGContextSetLineWidth(ctx, lineWidth); 

CGContextSetStrokeColorWithColor(ctx, textColor.CGColor); 
//---this works with iOS7 
//CGContextSetFillColorWithColor(ctx, textColor.CGColor); 
CGContextSetTextDrawingMode(ctx, kCGTextStroke); 
CGContextSetShadowWithColor(ctx,CGSizeMake(0,0),shadowThickness,[shadowColor CGColor]); 

[text drawAtPoint:textStartPont withFont:font]; 

CGContextRestoreGState(ctx);} 

为什么?

+0

可能是他们decrepated从iOS的7 –

+0

我检查。没有弃用,只有不同的行为。谢谢 – RobCat

回答

0

drawAtPoint:withFont:正在其中使用是deprecated in iOS7

drawAtPoint:withFont:

用指定的字体绘制字符串中在当前图形上下文指定点的单个线。 (iOS中7.0弃用使用drawAtPoint:withAttributes:不是。)