UILabel doesn't show emoji
I am having a problem displaying emoji in UILabel. I am getting this data from a web service (I cannot change the way I get the data): This value is relative to the debugger:
__NSCFString * @"emoji \\ud83d\\ude1b\\ud83d\\ude1d" 0x000000017405ea80
Value from NSLog:
emoji \ud83d\ude1b\ud83d\ude1d
if I assign this value to my text property UILabel, I get on 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;
and when i try:
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
NSString *output = [[NSString alloc] initWithData:data encoding:NSNonLossyASCIIStringEncoding];
I am getting emoji on screen, but if the string does not contain emoji inside, it will be nil and get an empty label on the device.
I cannot get it to work correctly.
Thanks for any help.
source to share
I tried your code, the second ... and it works great:
Here's what I have:
and the output is:
deleting the emoji line \\ud83d\\ude1b\\ud83d\\ude1d
just leave emoji
. this is using a simulator, I am wondering that the error only appears on the device? while in the simulator does it work?
source to share