問題描述
我正在將 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];
推薦答案
你的標(biāo)簽很模糊,因為框架使用了浮點數(shù).
Your label is blurry because the frame is using floating numbers.
要強(qiáng)制為你的框架設(shè)置整數(shù)值:
To force integers value for your frame just do :
[loadingText setFrame:CGRectIntegral(loadingText.frame)];
您也可以將構(gòu)成框架的所有值轉(zhuǎn)換為 int
,但 CGRectIntegral
會為您完成所有工作.
You could also cast all your values composing your frame to int
, but CGRectIntegral
does all the job for you.
這篇關(guān)于以編程方式添加時模糊 UILabel的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!