I'm at my wits end. I've tried what I think is everything to get rid of CATextLayer
blurriness to no avail. Admittedly, some things help, but text is still far too blurry when zoomed in 2x and nowhere near the crispness of non-CATextLayer
text.
Here's my situation. I've got a layer-hosted view which can contain many sublayers, including CATextLayers
(inside a custom CALayer
container). Now, the user can zoom the main content layer (which contains all the sublayer content) and this is done by applying a scale transform to the content layer.
Here are the things I'm currently doing. Most make a difference, though not a huge difference. If I zoom in all the way (which is 2x scale factor) I get seriously blurry text.
Ensure integral coordinates - works and makes an appreciable difference, but still far too blurry at 2x scale
Turn off shadows on
CATextLayer
container layers - makes a difference though not at 2x scaleEnsure background color of text layer is fully opaque - seems to make a difference though not at 2x scale
Set the
contentsScale
property to the window backing scale factor for all layers - seems to make a difference though not at 2x scaleOverride
-drawInContext:
of this customCATextLayer
subclass to smooth, anti-alias, and sub-pixel quantize the hell out of everything - fonts render much truer, but still blurry at 2x scale
Code fragment:
- (void) drawInContext:(CGContextRef)context
{
// Allow font smoothing.
CGContextSetAllowsAntialiasing(context, YES);
CGContextSetAllowsFontSmoothing(context, YES);
CGContextSetAllowsFontSubpixelPositioning(context, YES);
CGContextSetAllowsFontSubpixelQuantization(context, YES);
// Set drawing attributes.
CGContextSetStrokeColorWithColor(context, self.foregroundColor);
CGContextSetFillColorWithColor(context, self.backgroundColor);
CGContextFillRect(context, self.bounds);
// Font smoothing.
CGContextSetShouldAntialias(context, YES);
CGContextSetShouldSmoothFonts(context, YES);
CGContextSetShouldSubpixelPositionFonts(context, YES);
CGContextSetShouldSubpixelQuantizeFonts(context, YES);
[super drawInContext:context];
}
What am I missing?