17

我正在将 UILabel 添加到用于加载目的的视图中。但是,添加后它变得模糊。奇怪的是,我在 UITableViewController 上加载的加载视图的代码几乎相同,并且在那里工作得很好。然而,UIViewController 之上的这个是模糊的。

这是我的代码:

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];
4

3 回答 3

59

您的标签很模糊,因为框架使用的是浮点数。

要为您的框架强制整数值,只需执行以下操作:

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

您还可以将构成框架的所有值转换为int,但CGRectIntegral会为您完成所有工作。

于 2011-11-09T14:33:54.853 回答
15

除了 float/int 问题外,调用setShouldRasterizeUILabel 的父视图也会导致出现此问题。

于 2013-05-02T04:51:09.000 回答
3

对于那些无法使用以前答案的人,我发现如果我关闭该autoresizingmask功能,它就会调用该setShouldRasterize方法。

[loadingText setTranslatesAutoresizingMaskIntoConstraints:NO];

因此,如果您将此行注释掉,它将正确显示

于 2013-05-23T23:13:04.307 回答