ios – NSLayoutManager: How to prevent creating a separate glyph for emojis


I am using an UITextView and customised NSLayoutManager to draw text with a background. For this I assign an underlined NSAttributedString to the UITextView and then override the drawUnderline of the NSLayoutManager to draw the background instead of drawing the underline. This works quite well because with regular text we just get one glyph per line.

enter image description here

However if emojis are added to the string the NSLayoutManager creates a separate glyph for the emojis which then breaks the design because drawUnderline is called for every separate glyph range hence the backgrounds do overlap with each other then.

enter image description here

I tried to only draw one background per line but it turned out to be less reliable than expected. Is there any possibility to stop the NSLayoutManager from creating a separate glyph for the emojis?

I appreciate the help!

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img