xoudini / emojica

A Swift framework for using custom emoji in strings.
Apache License 2.0
106 stars 15 forks source link

How do I use this framework to replace all Emojis in labels with Twemoji? #1

Closed googlercolin closed 7 years ago

googlercolin commented 7 years ago

Hello Xoudini,

Thank you for your effort put into this project. May I know how do I use your framework to replace all Emojis displayed to users in labels with custom emoji (Twemoji) instead of Apple Color Emoji?

Thanks once again!

xoudini commented 7 years ago

Hi!

After importing the image set, you can use Twemoji on UILabel objects in the same way as on UITextView, i.e. by setting the object's attributedText to the converted output. If uncertain, you can always check if the object has an attribute named emojicaText, which can be used instead of attributedText if you wish, but doesn't really make a difference.

Example usage:

let emojica = Emojica()
@IBOutlet weak var label: UILabel!

override func viewDidLoad() {
    super.viewDidLoad()
    emojica.imageSet = Emojica.ImageSet.twemoji
    label.emojicaText = emojica.convert(string: "Example: \u{1f004}")
}

Let me know if this solved your issue!

googlercolin commented 7 years ago

Thanks for your help Dan! However, may I know where do I import the images for Twemoji? 😅

xoudini commented 7 years ago

Absolutely, no problems!

Just follow the links at https://github.com/xoudini/emojica#compatible-image-sets for the image set you want to use and clone the repo, in your case follow this link for twemoji.

From the twemoji repo you'll want to use the images at the path twemoji/2/72x72. Note that twemoji files aren't out-of-the-box compatible, so you'll need to follow the instructions at https://github.com/xoudini/emojica#preparations to prepare the image files for use (this has to do with the naming convention of the images – since I've made the conversion method as simple as possible I decided that it's easier to make different image sets conform to one standard rather than accounting for all different naming conventions in the code).

You can test the image set in the provided example app; just drag the "prepared" image set into the Images group in the example project and run. Make sure that the images have EmojicaExample checked in the Target Membership pane of the File Inspector.

Hope this helps!