Why can't Emoji display correctly in a UITextField?

后端 未结 1 1325
悲哀的现实
悲哀的现实 2021-01-01 02:22

When an Emoji character is set using the code below:

self.textField.text = @\"\\ue415\";

It just display as a square. But when I input an E

相关标签:
1条回答
  • 2021-01-01 02:52

    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

    0 讨论(0)
提交回复
热议问题