Retina显示核心图形字体质量

时间:2011-03-24 04:05:25

标签: iphone ios core-animation core-graphics calayer

试图理解为什么我使用CGContextShowTextAtPoint获得低质量的绘图?见附图: img

字母“W”是在CALayer上使用CGContextShowTextAtPoint绘制的,看起来非常像素化。它旁边的按钮是一个标准按钮,按预期看起来很高。我想让文字绘图成为高分辨率。

enter image description here

4 个答案:

答案 0 :(得分:36)

默认情况下,您的CALayer不会以更高的Retina显示屏分辨率渲染其Quartz内容。您可以使用以下代码启用此功能:

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

这不仅会影响文本渲染,还会影响CALayers中的所有Quartz绘图,因此您需要使用自定义Quartz内容对所有图层执行此操作。

答案 1 :(得分:5)

使用CGContextScaleCTM是否可以为您提供任何结果?使用图形上下文时,如下所示:

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

答案 2 :(得分:1)

一组函数控制Core Graphics如何呈现字体:

  • CGContextSetAllowsAntialiasing
  • CGContextSetAllowsFontSmoothing
  • CGContextSetAllowsFontSubpixelPositioning
  • CGContextSetAllowsFontSubpixelQuantization

答案 3 :(得分:1)

Swift版本:

textLayer.contentsScale = UIScreen.mainScreen().scale

enter image description here

相关问题