我创建了一个显示一个大字符的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-Bittalic),该角色延伸了SizeWithFont返回的内容。此外,Uilabel的框架(橙色)也将角色夹住。想法?也许我可以覆盖一些文本绘图例程。另外,不确定这是否与这里相同:

uibutton.titlelabel剪切文本问题

有帮助吗?

解决方案 2

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

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top