Why is UILabel text blurred on the iPad if the width is not even specified?

The following phenomenon: my text is โ€œSearchโ€. I create a UILabel for SmallSystemFontSize and call sizeToFit:

The result is 39 units wide and the text appears blurry. If I adjust the width to 40, it looks perfect.

I read that the text is blurred if you click on the subpixels, that is, the width will be approximately 39.5, but it seems to be flat.

Can someone confirm or even explain what is happening?

+6
source share
2 answers

UIView elements are centered, which for an odd size is located on the half-pixel, 19.5 for a width of 39. This alignment causes pixel averaging, which causes blurring.

One way is to make it equal width.

Another is to center it when using even points:

 @property(nonatomic) CGPoint center 

For example, for the desired label; position label; in (10, 10, 39, 19) one could use:

 label.center = CGPointMake(50, 20); 
+4
source

In my case, the culprit was to set shouldRasterize = YES to CGLayer overseeing UILabel. Removing this line made the text pleasant and clear.

+3
source

Source: https://habr.com/ru/post/901215/


All Articles