简体   繁体   English

快速在文本字段中显示带有字符串的表情符号

[英]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.我还需要将它们发送到服务器,因为应用程序是多平台的。

On Xcode version 7.2.1+, you can use the below shortcut to show the symbols panels and insert the emoji:在 Xcode 7.2.1+ 版本上,您可以使用以下快捷方式来显示符号面板并插入表情符号:

Shortcut: (press the below three keys together)快捷键:(同时按下下面三个键)

Ctrl + Command + Space Ctrl +命令+空格

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:您可以使用其 unicode 编号(1F603 是开放式笑脸的 unicode 编号)声明一个包含文本和表情符号的字符串变量,如下所示:

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

Then with your UITextField/UILabel, set the .text attribute to be the string.然后使用您的 UITextField/UILabel,将 .text 属性设置为字符串。

yourTextField.text = str
//or for a UILabel.
yourLabel.text = str
textField.text=@"😀";

for above Emoji --- put the focus at place of emoji in UITextField and go to对于上面的表情符号 --- 将焦点放在UITextField中表情符号的位置并转到

Edit > Emoji & Symbols in Xcode 7.3 and select what ever emoji you want.在 Xcode 7.3 中编辑 > 表情符号和符号,然后选择你想要的任何表情符号。

OR

Set Unicode values directly in code:直接在代码中设置 Unicode 值:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM