UILabel rendered in cgContext is blurry on Mac Catalyst

Hi,

The following code allow to build an image from an UILabel:

let label = UILabel()
label.text = "test content"
label.backgroundColor = .white
label.layer.cornerRadius = 10
label.layer.masksToBounds = true
label.sizeToFit()

let format = UIGraphicsImageRendererFormat()
format.scale = 5

let renderer = UIGraphicsImageRenderer(bounds: label.bounds, format:format)
let image: UIImage? = renderer.image { rendererContext in
    label.layer.render(in: rendererContext.cgContext)
}

This works perfectly on iOS but on Mac Catalyst the label text is very blurry as you can see in the image below.

Both images are created with the same exact code and have the exact same resolution of 460x103. On top the iOS version and on bottom the Mac Catalyst version.

Note that not all of the image is blurry, but only the text. In the code I set a corner radius of 10 and you can see that the corner is rendered with an high resolution, like the iOS version. It's just the text that for some reason is blurry. It's like if the label text is rendered with a scale of 1 and then scaled up.

Someone know why? There is something I can do to improve the rendering of the text?

Thank you

Are you running this in Pad idiom, or Mac idiom?

UILabel rendered in cgContext is blurry on Mac Catalyst
 
 
Q