[英]Why is NSTextAttachment image not displayed?
I'm trying to add an image to an attributed string: 我正在尝试将图像添加到属性字符串:
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];
Then I simply set myLabel.text = string;
然后我只需设置
myLabel.text = string;
(where myLabel
is a TTTAttributedLabel
) (其中
myLabel
是TTTAttributedLabel
)
location-pin-icon
is a valid image (I've checked it in debugging too). location-pin-icon
是有效的图片(我也在调试中检查过它)。 However, the location pin icon is not being displayed in the label (the following "some text" is displayed perfectly though, and linkAttributes
is just a collection of system font with a custom blue color). 但是,位置图钉图标并未显示在标签中(尽管以下“某些文本”显示得很完美,并且
linkAttributes
只是具有自定义蓝色的系统字体的集合)。 I've also tried manually setting bounds to the text attachment, or leaving a space before the text, but nothing seems to work. 我也尝试过手动设置文本附件的边界,或在文本前留一个空格,但似乎没有任何效果。
What am I doing wrong? 我究竟做错了什么?
It was apparently due to implementation of TTTAttributedLabel
. 显然是由于实现了
TTTAttributedLabel
。 The library seems broken. 图书馆好像坏了。 When I've switched from it, the attachment started displaying correctly.
从中切换后,附件开始正确显示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.