为什么表情符号在UITextField中无法正确显示? [英] Why can't Emoji display correctly in a UITextField?
问题描述
使用以下代码设置表情符号字符时:
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 Emoji from the keyboard it displays correctly. What's the problem?
PS:我正在使用IOS 5.1
< img src =https://i.stack.imgur.com/SOgKh.pngalt =带表情符号文字视图>
推荐答案
在旧版本的iOS中,表情符号字符都在Unicode专用区域中,顾名思义就是一组明确没有任何关联字符的Unicode代码点。但是,Unicode标准已更新为包含大量表情符号字符,因此iOS现在使用这些字符,Mac OS X也是如此。
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.
您可以看到一个列表www.unicode.org/charts中代码表中所有Unicode表情符号的例子 http://www.unicode.org/charts/PDF/U1F600.pdf 这些也告诉你每个表情符号实际上代表什么。
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.
Unicode规范的基本多语言平面中没有任何Unicode表情符号,这意味着它们'太大了,不适合单一的iOS unichar。因此,当它们存储在NSString中时,每个表情符号将覆盖多个unichars - 如果您尝试迭代字符串中的字符,则需要注意。
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.
如果你有类似的代码
NSString *emoji =@"\U0001F604";
NSString *ascii = @"A";
NSLog(@"emoji.length %d, ascii.length %d", emoji.length, ascii.length);
你会在输出中看到这个
2013-03-08 14:42:22.841 test[23980:c07] emoji.length 2, ascii.length 1
这篇关于为什么表情符号在UITextField中无法正确显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!