NSAttributedString使用图像和文本时,高度似乎对齐错误

时间:2014-12-08 09:21:03

标签: ios uilabel nsattributedstring nstextattachment

我在tableviewcell中有一个uilabel,标签使用NSAttributeString来支持图像和文本。但我发现当标签只包含图片或文字时,标签的高度是正确的,但是当标签包含图像和文本时,高度似乎都不正确。行高似乎比实际高度需要的大一点

enter image description here

如果只有文字或图片,则身高正确

enter image description here

我正在使用来自NSTextAttachment的我自己的子类来构建图像 enter image description here

并且附件代码是这样的 enter image description here

1 个答案:

答案 0 :(得分:0)

好的,这行代码看起来很有用,但我还是不知道为什么这么做             [textAttributeString addAttribute:NSBaselineOffsetAttributeName value:[NSNumber numberWithFloat:-4] range:NSMakeRange(0,textAttributeString.length)];