How can I keep an NSTextAttachment from line-break

2020-03-05 02:31发布

问题:

I'm trying to set a UILabel using an NSAttributableString like so:

(x)First Item (x)Second Item (x)Third Item

Where the (x)'s represent small images loaded through NSTextAttachments. The problem is, since each (x) is an icon representing it's item, I don't want UILabel to ever break the line between the (x) and its item. I've checked that there's absolutely nothing (that I can see) between the icon and the first character of the text, but this problem even shows up in TextEdit:

How can I always keep the text attachment on the same line as its text?

回答1:

Got it: word-joiner unicode \u2060.