English 中文(简体)
Blurry UILabel在加入方案时
原标题:Blurry UILabel when added programmatically

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];
最佳回答

你的标签模糊不清,因为框架使用的是浮动数字。

3. 强迫愤怒对你的框架的价值只是:

[loadingText setFrame:CGRectIntegral(loadingText.frame)];

你还可以把你构成你的框架的所有价值观放到<条码>int,但CGRectIntegral对你来说都是如此。

问题回答

除了浮标/特质问题外,如果在母体看来,打电话setShouldRasterize,也可导致出现这一问题。

对于无法使用先前答案的各位,我发现,如果我放弃了<代码>autoresizingmask。 它称为setShouldRasterize方法。

[loadingText setTranslatesAutoresizingMaskIntoConstraints:NO];

因此,如果你这样说的话,就会正确显示。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签