Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blurry UILabel when added programmatically

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 which is loaded ontop of an UITableViewController and it works great there. Yet, this one on top of an UIViewController is blurry.

This is my code:

float x = (self.view.frame.size.width-20)/2;
float y = (self.view.frame.size.height-70)/2;

// Add loading and sub text
UILabel *loadingText = [[UILabel alloc] initWithFrame:CGRectMake(10, round(y+30), round(self.view.frame.size.width-20), 21)];
[loadingText setTextAlignment:UITextAlignmentCenter];
[loadingText setNumberOfLines:0];
[loadingText setFont:[UIFont systemFontOfSize:17]];
[loadingText setText:NSLocalizedString(@"Please wait...\nWe are processing your request", @"LoadingPage")];
[loadingText sizeToFit];
[loadingText setBackgroundColor:[UIColor clearColor]];
[loadingText setCenter:self.view.center];
[loadingText setTag:2];

[view addSubview:loadingText];
like image 594
Paul Peelen Avatar asked Nov 09 '11 13:11

Paul Peelen


People also ask

How do you blur UILabel?

A subclass of UILabel, which the content can be blurred by setting `blurRadius` property.

What is UILabel?

A view that displays one or more lines of informational text.


2 Answers

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.

like image 61
NSZombie Avatar answered Oct 27 '22 02:10

NSZombie


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

like image 26
oskare Avatar answered Oct 27 '22 01:10

oskare