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


基础教程推荐
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01