以编程方式添加模糊UILabel [英] Blurry UILabel when added programmatically

查看:109
本文介绍了以编程方式添加模糊UILabel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这是我的代码:

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


推荐答案

您的标签模糊,因为框架使用浮动数字。

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

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

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

这篇关于以编程方式添加模糊UILabel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆