Blurry UILabel when added programmatically

前端 未结 3 2080
孤街浪徒
孤街浪徒 2020-12-14 03:00

I am adding a UILabel to a view meant for loading purposes. However, it gets blurry after I added it. The weird thing is that I just about the same code for an loading view

相关标签:
3条回答
  • 2020-12-14 03:20

    Your label is blurry because the frame is using floating numbers.

    To force integers value for your frame just do :

    [loadingText setFrame:CGRectIntegral(loadingText.frame)];
    

    You could also cast all your values composing your frame to int, but CGRectIntegral does all the job for you.

    0 讨论(0)
  • 2020-12-14 03:30

    For those of you that couldn't use the previous answers, I found that if I turned off the autoresizingmask feature it called the setShouldRasterize method.

    [loadingText setTranslatesAutoresizingMaskIntoConstraints:NO];
    

    thus if you comment this line out, it will display correctly

    0 讨论(0)
  • 2020-12-14 03:36

    Apart from the float/int issue, calling setShouldRasterize on the parent view of the UILabel can also cause this problem to appear.

    0 讨论(0)
提交回复
热议问题