5

I am new to swift development. I need to show the emoji inside the text field and labels. I also need to send them to server because Application is multi-platform.

Raj Aggrawal
  • 761
  • 1
  • 6
  • 21

3 Answers3

10

On Xcode version 7.2.1+, you can use the below shortcut to show the symbols panels and insert the emoji:

Shortcut: (press the below three keys together)

Ctrl + Command + Space

aheze
  • 24,434
  • 8
  • 68
  • 125
shivamkaushik
  • 374
  • 1
  • 12
9

You can declare a string variable with text and an emoji inside using its unicode number (1F603 is unicode number for an open faced smiley), like so:

let str : String = "Smiley \u{1F603}"

Then with your UITextField/UILabel, set the .text attribute to be the string.

yourTextField.text = str
//or for a UILabel.
yourLabel.text = str
mdhomer
  • 490
  • 5
  • 10
  • Is this unicode iOS only or can be used on all platforms – Raj Aggrawal Jul 07 '16 at 08:54
  • 3
    Unicode Defination - an international encoding standard for use with different languages and scripts, by which each letter, digit, or symbol is assigned a unique numeric value that applies across different platforms and programs. So yeah, It will be consistent on other platforms. – shivamkaushik Jul 07 '16 at 08:56
  • @shivamkaushik Please give me any source of Unicode to clear out the topic – Raj Aggrawal Jul 07 '16 at 10:37
  • 1
    Here is an extensive list of Emoji codes. Use the five characters after the U+ http://www.unicode.org/emoji/charts/full-emoji-list.html – Ben Jul 15 '20 at 02:23
5
textField.text=@"";

for above Emoji --- put the focus at place of emoji in UITextField and go to

Edit > Emoji & Symbols in Xcode 7.3 and select what ever emoji you want.

OR

Set Unicode values directly in code:

var string: String = "I want to visit मुंबई. "
var character: Character = ""

Use hexadecimal to set values

var string: String = "\u{61}\u{5927}\u{1F34E}\u{3C0}"

var character: Character = "\u{65}\u{301}"
Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165