Raj Aggrawal
Raj Aggrawal

Reputation: 761

Showing Emoji with string in textfield in swift

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.

Upvotes: 5

Views: 16727

Answers (3)

shivamkaushik
shivamkaushik

Reputation: 374

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

Upvotes: 10

Arjun Singh Baghel
Arjun Singh Baghel

Reputation: 135

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}"

Upvotes: 5

mdhomer
mdhomer

Reputation: 489

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

Upvotes: 9

Related Questions