emoji not being displayed, weird characters instead

本小妞迷上赌 提交于 2019-12-23 20:19:08

问题


I'm trying to display an emoji (ascii #55357) in CoreText and this is what I'm getting:

It displays two of these characters and inserts the cursor in the middle. I'm not going to include my CoreText code because it's such a mess and I have no idea where the bug is originating from, but what I was just curious has anyone else seen the same problem before in any facet of iOS and what is the meaning of these sort of A in a black and white box characters that got displayed? Does it mean invalid character or something? Just looking for some hints on how to even approach this problem.


回答1:


The problem was that I didn't realize an emoji character has a length of 2 and not 1 like most other characters. So what specifically was causing the issue was I was applying attributes to the emoji when adding it to my NSMutableAttributedString over a length 1 instead of 2. When I changed it to 2 it fixed it:

[self.text addAttributes: attributes range:NSMakeRange(self.cursor.position, 2 /* not 1 */)]


来源:https://stackoverflow.com/questions/23745653/emoji-not-being-displayed-weird-characters-instead

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!