Implement Emoticons in xcode

不羁岁月 提交于 2019-12-05 06:22:47

问题


I am tryingt o build an application where I am giving user liberty to add the emojis as in GTalk (e.g. :P :) :( ...). But I am not able to figure out the exact way to handle and display them once the characters are entered by the user.

Kindly pour in ideas for the same, as any form of help could trigger a solution for this.


回答1:


For inputs you can use custom buttons, setting their titles with the unicode representation of the emojis. Iphone has native support for this.

[myButton setTitle:@"\ue415" forState:UIControlStateNormal];

For display it in a textbox you have to handle this as a single char of a string so you can concatenate your regular text with emojis.

A complete list of emojis are listed in this page: http://pukupi.com/post/1964/

Edit: You can use a conversion table

:) = \ue415 :( = \ue40e ....

You can use that conversion table with using images instead unicode chars but it is very complicated if you want to merge text and images in the same paragraph. Here is an example using a property list if you want to use images

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>SparkSetVersion</key>
        <integer>1</integer>
        <key>Emoticons</key>
        <dict>
            <key>angry.png</key>
            <dict>
                <key>Equivalents</key>
                <array>
                    <string>&gt;:o</string>
                    <string>&gt;:-o</string>
                    <string>&gt;:O</string>
                    <string>&gt;:-O</string>
                    <string></string>
                </array>
                <key>Name</key>
                <string>Angry</string>
            </dict>
            <key>blush.png</key>
            <dict>
                <key>Equivalents</key>
                <array>
                    <string>:-[</string>
                </array>
                <key>Name</key>
                <string>Blush</string>
            </dict>
            <key>confused.png</key>
            <dict>
                <key>Equivalents</key>
                <array>
                    <string>?:|</string>
                </array>
                <key>Name</key>
                <string>Confused</string>
            </dict>
            <key>cool.png</key>
            <dict>
                <key>Equivalents</key>
                <array>
                    <string>B-)</string>
                </array>
                <key>Name</key>
                <string>Cool</string>
            </dict>
            <key>cry.png</key>
            <dict>
                <key>Equivalents</key>
                <array>
                    <string>:'(</string>
                    <string></string>
                </array>
                <key>Name</key>
                <string>Cry</string>
            </dict>
            <key>devil.png</key>
            <dict>
                <key>Equivalents</key>
                <array>
                    <string>]:)</string>
                </array>
                <key>Name</key>
                <string>Devil</string>
            </dict>
            <key>grin.png</key>
            <dict>
                <key>Equivalents</key>
                <array>
                    <string>:-D</string>
                    <string>:D</string>
                    <string></string>
                </array>
                <key>Name</key>
                <string>Grin</string>
            </dict>
            <key>happy.png</key>
            <dict>
                <key>Equivalents</key>
                <array>
                    <string>:-)</string>
                </array>
                <key>Name</key>
                <string>Happy</string>
            </dict>
            <key>laugh.png</key>
            <dict>
                <key>Equivalents</key>
                <array>
                    <string>:^0</string>
                </array>
                <key>Name</key>
                <string>Laugh</string>
            </dict>
            <key>love.png</key>
            <dict>
                <key>Equivalents</key>
                <array>
                    <string>:x</string>
                </array>
                <key>Name</key>
                <string>Love</string>
            </dict>
            <key>mischief.png</key>
            <dict>
                <key>Equivalents</key>
                <array>
                    <string>;\</string>
                </array>
                <key>Name</key>
                <string>Mischief</string>
            </dict>
            <key>mischief.png</key>
            <dict>
                <key>Equivalents</key>
                <array>
                    <string>;\</string>
                </array>
                <key>Name</key>
                <string>Mischief</string>
            </dict>

            <key>sad.png</key>
            <dict>
                <key>Equivalents</key>
                <array>
                    <string>:-(</string>
                    <string>:(</string>
                    <string></string>
                </array>
                <key>Name</key>
                <string>Sad</string>
            </dict>
            <key>smile.png</key>
            <dict>
                <key>Equivalents</key>
                <array>
                    <string>:-)</string>
                    <string>:)</string>
                    <string></string>
                </array>
                <key>Name</key>
                <string>Smile</string>
            </dict>
            <key>silly.png</key>
            <dict>
                <key>Equivalents</key>
                <array>
                    <string>:-p</string>
                    <string>:-P</string>
                    <string>:P</string>
                    <string>:p</string>
                    <string></string>
                </array>
                <key>Name</key>
                <string>Tongue</string>
            </dict>
            <key>cool.png</key>
            <dict>
                <key>Equivalents</key>
                <array>
                    <string>8-)</string>
                    <string></string>
                </array>
                <key>Name</key>
                <string>Cool</string>
            </dict>
            <key>wink.png</key>
            <dict>
                <key>Equivalents</key>
                <array>
                    <string>;-)</string>
                    <string>;)</string>
                    <string></string>
                </array>
                <key>Name</key>
                <string>Wink</string>
            </dict>
        </dict>
    </dict>
</plist>


来源:https://stackoverflow.com/questions/5659935/implement-emoticons-in-xcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!