Skip to content
This repository has been archived by the owner on Aug 15, 2019. It is now read-only.

Latest commit

 

History

History
61 lines (33 loc) · 3.32 KB

USAGE.md

File metadata and controls

61 lines (33 loc) · 3.32 KB

Emojione iOS Usage

Initialization

Start by importing the Emojione iOS library.

import emojione_ios

Instantiate the Emojione client using the default rule set.

let client = Client()

If you have a custom rule set, you can pass it in the initializer. init()

let client = Client(MyRuleSet())

The default ruleset is recommended.

Client Properties

The following properties are available in the Swift/iOS version of the Emojione library:

  • emojiVersion (string) - Used only to direct CDN path. This is a 2-digit version (e.g. '3.1'). Not recommended for usage below 3.0.0.
  • emojiSize (enum) Default: 32 - Used only to direct CDN path for non-sprite PNG usage. Available options are '32', '64', and '128'.
  • imagePathPNG (string) - Defaults to CDN (jsdelivr) path. Setting as alternate path overwrites emojiSize option.
  • greedyMatch (bool) Default: false - When true, matches non-fully-qualified Unicode values.
  • ascii (bool) Default false - When true, matches ASCII characters (in unicodeToImage and shortnameToImage functions).
  • riskyMatchAscii (bool) Default false - When true, matches ASCII characters not encapsulated by spaces. Can cause issues when matching (e.g. C://filepath or <button>.</button> both contain ASCII chars).

Usage Examples

Below there are some examples of how you will actually use the libraries to convert Unicode emoji characters to :shortnames: and :shortnames: to emoji images.

Client Functions

client.toShort(String) -> String - native unicode -> shortnames

Take native unicode emoji input and translate it to their corresponding shortnames. (we recommend this for database storage)

client.shortnameToImage(String, UIFont) -> NSAttributedString - shortname -> images client.shortnameToImageAsync(String, UIFont, (NSAttributedString) -> Void) - shortname -> images

Take input containing only shortnames and translate it directly to EmojiOne images (when displaying the unified input to clients). The UIFont parameter is used to calculate the line height to display the emoji image appropriately. The asynchronous version takes a callback as the third argument.

client.shortnameToUnicode(String) -> String - shortname -> native unicode emoji

Take input containing only shortnames and translate it directly to Unicode Emoji (when displaying the unified input to clients).

client.unicodeToImage(String, UIFont) -> NSAttributedString - native unicode -> images client.unicodeToImageAsync(String, UIFont, (NSAttributedString) -> Void) - native unicode -> images

Takes native unicode emoji input and translate it directly to EmojiOne images. The UIFont parameter is used to calculate the line height to display the emoji image appropriately. The asynchronous version takes a callback as the third argument.

client.toImage(String, UIFont) -> NSAttributedString - native unicode + shortnames -> images client.toImageAsync(String, UIFont, (NSAttributedString) -> Void) - native unicode + shortnames -> images

Takes a string containing both native unicode emoji and shortnames, and translate it into EmojiOne images for display. The UIFont parameter is used to calculate the line height to display the emoji image appropriately. The asynchronous version takes a callback as the third argument.