开发者

Retina display core graphics font quality

Trying to understand why am I getting low quality drawing with CGContextShowTextAtPoint? See attached image:

Retina display core graphics font quality

The letter "W" is drawn using CGContextShowTextAtPoint on a CALayer and looks very pixelized. The button next to it is a standard button a开发者_如何学Pythonnd looks high res as expected. I would like to get the text drawing to be hi-res.

Retina display core graphics font quality


By default, your CALayer is not rendering its Quartz content at the higher resolution of the Retina display screen. You can enable this using code like the following:

if ([layer respondsToSelector:@selector(setContentsScale:)])
{
    layer.contentsScale = [[UIScreen mainScreen] scale];
}

This will affect not just text rendering, but all of your Quartz drawing within CALayers, so you'll need to do this for all of your layers with custom Quartz content.


Does using CGContextScaleCTM deliver any results for you? When working with a graphics context, something like this:

CGFloat scale = [[UIScreen mainScreen] scale];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextScaleCTM(context, scale, scale);


Swift version:

textLayer.contentsScale = UIScreen.mainScreen().scale

Retina display core graphics font quality


A group of functions controls how Core Graphics renders fonts:

  • CGContextSetAllowsAntialiasing
  • CGContextSetAllowsFontSmoothing
  • CGContextSetAllowsFontSubpixelPositioning
  • CGContextSetAllowsFontSubpixelQuantization
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜