以编程方式添加时模糊 UILabel

Blurry UILabel when added programmatically(以编程方式添加时模糊 UILabel)
本文介绍了以编程方式添加时模糊 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)