为什么不显示 NSTextAttachment 图片?
Why is NSTextAttachment image not displayed?
我正在尝试将图像添加到属性字符串:
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;
(其中myLabel
是一个TTTAttributedLabel
)
location-pin-icon
是一个有效的图像(我也在调试中检查过)。但是,位置图钉图标没有显示在标签中(尽管下面的 "some text" 完美显示,而 linkAttributes
只是具有自定义蓝色的系统字体的集合)。我也试过手动设置文本附件的边界,或者在文本前留下一个 space,但似乎没有任何效果。
我做错了什么?
这显然是由于 TTTAttributedLabel
的实施。图书馆似乎坏了。当我从它切换时,附件开始正确显示。
我正在尝试将图像添加到属性字符串:
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;
(其中myLabel
是一个TTTAttributedLabel
)
location-pin-icon
是一个有效的图像(我也在调试中检查过)。但是,位置图钉图标没有显示在标签中(尽管下面的 "some text" 完美显示,而 linkAttributes
只是具有自定义蓝色的系统字体的集合)。我也试过手动设置文本附件的边界,或者在文本前留下一个 space,但似乎没有任何效果。
我做错了什么?
这显然是由于 TTTAttributedLabel
的实施。图书馆似乎坏了。当我从它切换时,附件开始正确显示。