UILabel没有显示表情符号 [英] UILabel not showing emoji
问题描述
我遇到了在UILabel中显示表情符号的问题。
我从Web服务获取此数据(我无法更改获取数据的方式):
此值来自调试器:
I'm facing a problem about displaying emoji in a UILabel. I get this data from a web service (i cannot change the way i get the data) : This value is from the debugger :
__NSCFString * @"emoji \\ud83d\\ude1b\\ud83d\\ude1d" 0x000000017405ea80
NSLog的价值:
emoji \ud83d\ude1b\ud83d\ude1d
如果我将此值分配给我的UILabel文本属性,我会在屏幕上显示:
if i assign this value to my UILabel text property i get on the screen :
emoji \ud83d\ude1b\ud83d\ude1d
我尝试使用以下代码对字符串进行编码和解码:
I tried to encode and decode the string using :
NSData *data = [string dataUsingEncoding:NSNonLossyASCIIStringEncoding];
NSString *dataValue = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
return dataValue;
当我尝试时:
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
NSString *output = [[NSString alloc] initWithData:data encoding:NSNonLossyASCIIStringEncoding];
我在屏幕上显示表情符号,但如果字符串里面没有表情符号则会为零在设备上获取空标签。
i get the emoji on the screen but if a string does not have emoji inside it will be nil and get empty label on device.
我无法让它正常工作。
I can't get it to work correctly.
感谢您的帮助。
推荐答案
我尝试了您的代码,第二个......它运作得很好:
I tried your code, the second one.. and it is working perfectly:
这就是我所拥有的:
和输出:
删除表情符号字符串 \\\\�\\\\�\\\\�\\\\�
只需离开表情符号
。
这是使用模拟器,我不知道错误只出现在设备上?在模拟器中它工作吗?
removing the emoji string \\ud83d\\ude1b\\ud83d\\ude1d
just leave emoji
.
this is using simulator, i wonder the error only appear on the device? while in simulator it's working?
这篇关于UILabel没有显示表情符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!