Why can't Emoji display correctly in a UITextField?

放肆的年华 提交于 2019-11-30 09:58:31

In older versions of iOS the Emoji characters were all in the Unicode Private Use Area, which as the name suggests is a set of Unicode code points that explicitly don't have any associated characters. However, the Unicode standard has been updated to include a large number of Emoji characters, so iOS now uses these ones, as does Mac OS X.

You can see a list of all the Unicode Emoji in the code charts at www.unicode.org/charts e.g. http://www.unicode.org/charts/PDF/U1F600.pdf and these also tell you what each Emoji is actually meant to represent.

None of the Unicode Emoji are in the Basic Multilingual Plane of the Unicode spec, which means that they're all too big to fit in a single iOS unichar. So when they're stored in an NSString each emoji will cover multiple unichars — something to be aware of if you try to iterate over the characters in a string.

If you have code like

NSString *emoji =@"\U0001F604";
NSString *ascii = @"A";
NSLog(@"emoji.length %d, ascii.length %d", emoji.length, ascii.length);

You'll see this in the output

2013-03-08 14:42:22.841 test[23980:c07] emoji.length 2, ascii.length 1

where the single 😄 SMILING FACE WITH OPEN MOUTH AND SMILING EYES emoji is two unichars long, not one as we might expect.

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