2014-02-17 38 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:不是。)