为什么不显示NSTextAttachment图像?

时间:2017-06-25 09:22:26

标签: ios ios10 nsattributedstring

我正在尝试将图片添加到属性字符串中:

NSTextAttachment *locationIcon = [[NSTextAttachment alloc] init];
locationIcon.image = [UIImage imageNamed:@"location-pin-icon"];
NSAttributedString *iconString = [NSAttributedString attributedStringWithAttachment:locationIcon];
[string appendAttributedString:iconString];
NSAttributedString *locationNameString = [[NSAttributedString alloc] initWithString:@"some text" attributes:linkAttributes];
[string appendAttributedString:locationNameString];

然后我只设置myLabel.text = string;(其中myLabelTTTAttributedLabel

location-pin-icon是一个有效的图像(我也在调试中检查过它)。但是,位置图钉图标未显示在标签中(以下“某些文本”显示完美,而linkAttributes只是具有自定义蓝色的系统字体的集合)。我也尝试手动设置文本附件的边界,或在文本前留一个空格,但似乎没有任何效果。

我做错了什么?

1 个答案:

答案 0 :(得分:1)

显然是由于TTTAttributedLabel的实施。图书馆好像坏了。当我从它切换时,附件开始正确显示。