CGContext文本绘图无法在iPhone 4上扩展

Car*_*len 9 iphone core-graphics objective-c ios4 iphone-4

我正在尝试创建一个可以在iPhone 4上很好地扩展的应用程序.目前大多数都可以完美地扩展,除了一个关键部分:我在一个CALayer中绘制的文本,在其drawInContext:方法中.这是我的代码:

- (void)drawInContext:(CGContextRef)context {
    UIGraphicsPushContext(context);

    CGContextSetGrayFillColor(context, 1.0f, 1.0f);
    CGContextFillRect(context, self.bounds);

    CGContextSetAllowsAntialiasing(context, true);
    CGContextSetShouldAntialias(context, true);

    CGContextSetAllowsFontSmoothing(context, true);
    CGContextSetShouldSmoothFonts(context, true);

    CGContextSetAllowsFontSubpixelQuantization(context, true);
    CGContextSetShouldSubpixelQuantizeFonts(context, true);

    CGContextTranslateCTM(context, 0.0f, self.frame.size.height);
    CGContextScaleCTM(context, 1.0f, -1.0f);

    CGContextSetFillColorWithColor(context, [[UIColor blackColor] CGColor]);
    CGContextSelectFont(context, "CardKit", 30.0f, kCGEncodingMacRoman);
    CGContextSetTextDrawingMode(context, kCGTextFill);
    CGContextShowText(context, "A", sizeof("A"));

    UIGraphicsPopContext();
}
Run Code Online (Sandbox Code Playgroud)

这个简短的文章在两个设备上都会产生清晰的文字,但遗憾的是,它会在两个设备上产生模糊文字.以下是它的显示方式:

丑陋的文字http://files.droplr.com.s3.amazonaws.com/files/16285043/1gBp61.Screen%20shot%202010-06-26%20at%2021:25:09.png

该图像是在iPhone 4上以100%变焦拍摄的.世界上有什么?我有什么想法可以解决这个问题?

Nic*_*rge 27

您应该将图层设置contentsScale为与scale屏幕相同:

layer.contentsScale = [UIScreen mainScreen].scale;
Run Code Online (Sandbox Code Playgroud)

这将在所有iOS设备,Retina Display和非Retina Display上正确缩放.除非你有充分的理由这样做,否则你不应该将它硬编码到2.0(或其他任何事情).