我正在尝试将图像添加到属性字符串中:
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是一个有效的镜像(我在调试时也检查过它)。但是,位置针图标没有显示在标签中(下面的“一些文本”显示得很好,而linkAttributes只是系统字体的集合,带有自定义的蓝色)。我也尝试过手动设置文本附件的边界,或者在文本前留一个空格,但似乎都不起作用。
我做错了什么?
发布于 2017-10-11 23:18:51
这显然是由于TTTAttributedLabel的实现。图书馆好像坏了。当我从它切换时,附件开始正确显示。
https://stackoverflow.com/questions/44744963
复制相似问题