UILabel sizeWithFont:问题。剪切斜体文本
问题描述:
我创建了一个显示单个大字符的UILabel。即使有clipsToBounds = NO;我仍然得到剪裁。UILabel sizeWithFont:问题。剪切斜体文本
见链接:http://img341.imageshack.us/img341/5310/screenshot20100814at243.png
我用下面的代码:
CGSize fBounds = [myLabel.text sizeWithFont:cFont];
得到什么应该是字体的边框。并且所述标签被绘制:
myLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 280, 300)];
myLabel.clipsToBounds = NO;
myLabel.numberOfLines = 1;
myLabel.textAlignment = UITextAlignmentCenter;
myLabel.adjustsFontSizeToFitWidth = YES;
myLabel.minimumFontSize = 10;
myLabel.text = @"A";
myLabel.font = [UIFont fontWithName:@"CourierNewPSMT" size:300];
myLabel.textColor = [UIColor blackColor];
myLabel.backgroundColor = [UIColor colorWithRed:1 green:.5 blue:0 alpha:.5];
在下面的图像,从sizeWithFont返回的大小是由半透明的蓝色矩形覆盖呈现。正如你所看到的,用斜体字体(在这种情况下是Verdana-BoldItalic),字符延伸超过sizeWithFont返回的值。此外,UILabel的框架(橙色)也剪辑角色。思考?也许我可以重写一些文本绘图程序。另外,不知道这是因为这里同样的问题:
答
看起来这是一个苹果的问题。用CoreText完成自定义绘图。
+3
将会很有帮助。 – 2012-08-30 15:33:31
答
使用归属文字+缩进...
刚才碰到了这个。看起来应该是一个RDAR提交。如果您也可以共享解决方案,则 – 2010-11-19 23:48:39