Graphics Reference
In-Depth Information
elementum, libero ut porttitor dictum, diam odio congue lacus, vel \
fringilla sapien diam at purus. Etiam suscipit pretium nunc sit amet \
lobortis"
;
//set layer text
textLayer.
string
= text;
}
@end
Figure 6.2
A plain text label implemented using
CATextLayer
If you look at this text closely, you'll see that something is a bit odd; the text is pixelated.
That's because it's not being rendered at Retina resolution. Chapter 2 mentioned the
contentsScale
property, which is used to determine the resolution at which the layer
contents are rendered. The
contentsScale
property always defaults to 1.0 instead of
the screen scale factor. If we want Retina-quality text, we have to set the
contentsScale
of our
CATextLayer
to match the screen scale using the following
line of code:
textLayer.
contentsScale
= [
UIScreen
mainScreen
].
scale
;
This solves the pixelation problem (see Figure 6.3).