Mansi Panchal
Mansi Panchal

Reputation: 2357

Display Emoji in UITextField

I am trying to add emoji in UITextField with existing text.But I get only unicode in the textfield in place of emoji like \ue415. I have try the below code to set emoji in the textfield.

I have a view in which there are buttons with images of emojis. on the click of that emoji i am appending the respective unicode of that emoji to the text. but in that unicode is appended in string format and not the actual symbol.

If I try to set direct unicode in the textfield then it show the emoji but if i try to get the value from array then it is not showing the emoji.

NSString *strCode = [[arrPlist objectAtIndex:[sender tag]]objectForKey:@"UTFCode"];
strCode = [strCode stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

NSString *mycode = @"\ue415";
if ([mycode isEqualToString:strCode]) 
 {
     NSLog(@"both are same");
 }
NSLog(@"%@",[NSString stringWithFormat:@"strCode:%@ and mycode:%@",strCode,mycode]);
messageField.text = [messageField.text stringByAppendingFormat:@"%@ %@",strCode,mycode];

And the output is like :

strCode:\ue415 and mycode:

Can anyone help me with how can i get the strCode same as myCode ?

Upvotes: 3

Views: 4125

Answers (2)

TheTiger
TheTiger

Reputation: 13364

Interesting question.

you can not put \ character as a string. in your code 'mycode' takes the @"\ue415" in one character not as string. you can see it with

NSlog(@"%d",[mycode length]);

... it will show you 1 instead of 6.

if you can set -

NSString *mycode = [[NSString stringWithFormat:@"\\"]stringByAppendingFormat:@"ue415"]); 

any how in your code....this will give you the string what you want.

Thank You!!

Upvotes: 0

Narayana Rao Routhu
Narayana Rao Routhu

Reputation: 6323

Use like below it will work  

 NSString *myString = @"I am sad of him";
 myString = [myString stringByReplacingOccurrencesOfString:@"sad" withString:@"\ue415"];
 txtField.text = myString;

Upvotes: 2

Related Questions