[英]Programmatically set UILabel has blurry text (integer frame values)
我有一个视图,可以在viewDidLoad
编程方式设置UILabel。 该标签上的文字模糊。 编码:
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
[self setTitle:tAddSystemScreenTitle];
CGRect rect = CGRectMake(10,0,300,80);
UILabel *messageLabel = [[UILabel alloc] initWithFrame:rect];
[messageLabel setOpaque:NO];
if (shouldShowControlForRemoteAccess) {
[messageLabel setText:kRemoteAccessInfoMessage];
[messageLabel setNumberOfLines:2];
} else {
[messageLabel setText:kOneSystemAlreadyAssociatedAlertString];
[messageLabel setNumberOfLines:4];
rect.size.height += 30;
[messageLabel setFrame:rect];
rect = dataTable.frame;
rect.origin.y += 30;
rect.size.height -= 30;
[dataTable setFrame:rect];
}
NSLog(@"x: %f, y: %f, w: %f, h: %f", messageLabel.frame.origin.x, messageLabel.frame.origin.y, messageLabel.frame.size.width, messageLabel.frame.size.height);
[messageLabel setBackgroundColor:[UIColor clearColor]];
[messageLabel setShadowColor:[UIColor blackColor]];
[messageLabel setTextColor:[UIColor blackColor]];
[messageLabel setTextAlignment:UITextAlignmentLeft];
[messageLabel setShadowOffset:CGSizeMake(0,-1)];
[self.view addSubview:messageLabel];
NSLog(@"x: %f, y: %f, w: %f, h: %f", self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
[dataTable setScrollEnabled:NO];
[messageLabel release], messageLabel = nil;
}
当我检查帧值是多少时,得到以下信息:
x: 10.000000, y: 0.000000, w: 300.000000, h: 80.000000
检查self.view
相同:
x: 0.000000, y: 20.000000, w: 320.000000, h: 460.000000
在此问题上,我能找到的唯一 其他 问题是,我需要为框架使用整数,但是如您所见,我已经有了整数。 我尝试了他们推荐的解决方案,使用CGRectIntegral(rect)
替换了我刚刚使用rect
所有位置,但这没有用。 如何防止文字模糊?
我有同样的问题。 就我而言,原因是我在父视图上调用了setShouldRasterize。
也许事实是您的黑色文本带有稍微偏斜的黑色阴影,这使它看起来很模糊。 尝试删除您的shadowColor和shadowOffset线,看看它的外观。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.