Blurry UILabel when added programmatically(以编程方式添加时模糊 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...
We 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:以编程方式添加时模糊 UILabel
基础教程推荐
- 如何从 logcat 中删除旧数据? 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
