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?
stringdoes it appears? Also, where is your code where you set theattributedString? - LarmeUILabel(thenmyUILabel.attributedText = string;, does it work? It wasn't available yet (github.com/TTTAttributedLabel/TTTAttributedLabel/issues/287) The issue is a long time ago, but still. - Larmepoit, though it appears as an<NSTextAttachment: 0x1702a7080>object instead of a useful description. - Can Poyrazoğlu