Question

I Use this function to draw a custom UILabel. It works with iOS 6 and earlier but fails with iOS 7. If I replace CGContextSetStrokeColorWithColor with CGContextSetFillColorWithColor, it works with iOS7 but not with 6 and earlier.

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);}

why?

Was it helpful?

Solution

drawAtPoint:withFont: which you are using is deprecated in iOS7:

drawAtPoint:withFont:

Draws the string in a single line at the specified point in the current graphics context using the specified font. (Deprecated in iOS 7.0. Use drawAtPoint:withAttributes: instead.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top