简体   繁体   中英

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; (where myLabel is a TTTAttributedLabel )

location-pin-icon is a valid image (I've checked it in debugging too). 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). 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 . The library seems broken. When I've switched from it, the attachment started displaying correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM