I was working today on a custom UIView that performed some text animations on layers using CATextLayer, and I noticed that my text was being rendered blurry and fuzzy, specially on iPhone 6/6Plus. It’s been a long since I worked with CATextLayers, and I hadn’t noticed any blurriness before, maybe because it was in the early days of retina, and our eyes weren’t used to the crispy, clear lines of current iPhone displays (or maybe because I was too lazy back then).

Anyway, I discovered that the blurriness was due to the fact that the fonts in the CATextLayer were being rendered without anti-aliasing. It seems that, on normal UIKit components (UILabels, UIButtons, etc…), UIKit takes care of the antialiasing, but not so on layers. A simple solution is to set the contentsScale property of the CATextLayer to the exact same scale of the iPhone, which can be easily retrieved by calling UIScreen.mainScreen().scale.

let textLayer = CATextLayer()
loadingTextLayer.contentsScale = UIScreen.mainScreen().scale
loadingTextLayer.frame = ...
loadingTextLayer.string = "some text"
loadingTextLayer.font = "HelveticaNeue-Light"

Now the text layers are being rendered crisp and clear, even when rotating or applying custom transforms. If you find yourself in this situation, contentsScale is your friend.