UILabel sizeWithFont:问题。剪切斜体文本

时间:2010-08-14 19:26:38

标签: uilabel clipping uifont sizewithfont

我创建了一个显示单个大字符的UILabel。即使有clipsToBounds = NO;我还是剪掉了。

请参阅链接: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的框架(橙色)也会剪辑角色。思考?也许我可以覆盖一些文本绘图例程。此外,不确定这是否与此处相同:

UIButton.titleLabel clipping text problem

2 个答案:

答案 0 :(得分:0)

使用属性文字+缩进...

答案 1 :(得分:-3)

看起来这是一个苹果问题。结束了使用CoreText进行自定义绘图。