【问题标题】:CGContextSetStrokeColorWithColor fails with iOS 7CGContextSetStrokeColorWithColor 在 iOS 7 中失败
【发布时间】:2014-02-17 11:26:59
【问题描述】:

我使用这个函数来绘制一个自定义的 UILabel。它适用于 iOS 6 及更早版本,但适用于 iOS 7。如果我将 CGContextSetStrokeColorWithColor 替换为 CGContextSetFillColorWithColor,它适用于 iOS7,但不适用于 6 及更早版本。

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

为什么?

【问题讨论】:

  • 可能是他们从 iOS 7 中删除了它
  • 我查过了。没有弃用,只有不同的行为。谢谢

标签: ios7 core-graphics cgcontext


【解决方案1】:

你使用的drawAtPoint:withFont:deprecated in iOS7:

drawAtPoint:withFont:

使用指定字体在当前图形上下文中的指定点处以单行方式绘制字符串。 (在 iOS 7.0 中已弃用。请改用 drawAtPoint:withAttributes:。)

【讨论】:

    猜你喜欢
    • 2016-01-03
    • 1970-01-01
    • 2013-09-21
    • 1970-01-01
    • 1970-01-01
    • 2013-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多