A Swift framework for using custom emoji in strings.

Overview

emojica

Emojica – a Swift framework for using custom emoji in strings.

gif

What does it do?

Emojica allows you to replace the standard emoji in your iOS apps with custom emoji. Works on UILabel and UITextView.

Just follow the instructions below, import your custom image set, and you're ready to go.

Features

  • Compatible with all iOS 13 emoji
  • Works with any image set1
  • Safe to use even with incomplete image sets2
  • Convert input directly on textViewDidChange(_:)
  • Revert converted strings to their original representation
1. The naming should follow a similar pattern as the compatible image sets.
2. The original emoji are used as fallback.

Requirements

  • Xcode 11
  • iOS 13.0+
    • Lower versions haven't been tested, although the framework may run without issues on a lower version.
  • Swift 5
    • Using the framework in an Objective-C project may require some modifications to the source. Support for Objective-C will possibly be added at some point in the future.

Installation

CocoaPods

  1. Add the pod to your Podfile:
target '...' do
    pod 'Emojica'
end
  1. Navigate into your project directory and install/update:
$ cd /Path/To/Your/Project/ && pod install

Carthage

  1. Add this to your Cartfile:
github "xoudini/emojica"
  1. Navigate into your project directory and install/update:
$ cd /Path/To/Your/Project/ && carthage update

Swift Package Manager

Open your project use Xcode. Click File -> Add Packages, enter repository url.

https://github.com/xoudini/emojica

Manual installation

  1. Clone the repository, and drag Emojica.xcodeproj into your project hierarchy in Xcode.
  2. Select your project, then select your application's target under Targets.
  3. Under the General tab, click the + under Embedded Binaries.
  4. Select Emojica.frameworkiOS and finish by pressing Add.

If Xcode gives you a No such module 'Emojica' compiler error at your import statement, just build your application (or the framework) once. Also, each time you Clean (⇧⌘K) the project Xcode will give you the same error, and the solution is the same.

Usage

import Emojica

Instantiation

let emojica = Emojica()

// Creates an instance with a font.
let emojica = Emojica(font: UIFont.systemFont(ofSize: 17.0))

Configure instance

  • Set font:

    emojica.font = UIFont.systemFont(ofSize: 17.0)

If no font is set, the system font is used.

  • Set size:

    emojica.pointSize = 17.0

If you're satisfied with the default font, you can just set the size. The value for pointSize is 17.0 by default.

  • Set minimum code point width:

NOTE: Use this only when using a custom image set that isn't handled by Emojica.

emojica.minimumCodePointWidth = 4

A value between 0 and 8 that sets the minimum width for code point strings in order to correctly find the images for the custom emoji. The character 0 is used for padding.

To find a suitable value, find the image for e.g. © (U+00A9 COPYRIGHT SIGN), and use the length of that image's name – a9.png has a width of 2, 00a9.png has a width of 4, etc.

  • Set separator:

NOTE: Use this only when using a custom image set that isn't handled by Emojica.

emojica.separator = "~"

The separator used in the image names of combined code points.

  • Set image set used in the project:

    emojica.imageSet = .default

Automatically configures settings specific to the image set.

  • Disable modifier symbols:

    emojica.useModifiers = false

Strips out all modifier symbols from complete modifier sequences.

  • Enable emoji to be reverted:

NOTE: Keep the instance non-revertible if the original strings aren't needed after conversion.

emojica.revertible = true

Enables strings with custom emoji to be reverted to original state.

Convert string

let sample: String = "Sample text 😎"

let converted: NSAttributedString = emojica.convert(string: sample)

Revert string

NOTE: The instance must have revertible set to true.

let reverted: String = emojica.revert(attributedString: converted)

Using converted strings

let textView = UITextView()

...

let flag: String = "🇫🇮 "

textView.attributedText = emojica.convert(string: flag)

Directly converting text input

You can directly convert text input by implementing the UITextViewDelegate method textViewDidChange(_:) and passing the changed UITextView to the Emojica method by the same name:

func textViewDidChange(_ textView: UITextView) {
    emojica.textViewDidChange(textView)
}

Compatible Image Sets

The below image sets are tested, but other image sets may work just as well. If you have an image set that should be added to Emojica, please create an Issue.

Set Version Notes
Twemoji v13.0 Prepare
EmojiOne   2.2.7     Missing code points1
Noto Emoji 1.05 Prepare

NOTE: The newest EmojiOne and Noto sets haven't been checked in a while.

1. U+2640, U+2642 and U+2695 and sequences containing these characters are unsupported.

Example Project

The example EmojicaExample.xcodeproj is set up but does not contain images. To test the project, add your emoji images to the Images group and Run.

Preparations

WARNING: Running the script will overwrite the image names, so do not run the script over a unique image set!

Some image sets may have to be slightly modified before usage. Check the table in Compatible Image Sets if you're using a set marked Prepare, and if you are, follow these instructions:

1. Copy/move the contained file rename.sh into the folder containing your image set.

2. Open your preferred terminal.

3. Navigate into the directory:

$ cd /Path/To/Your/ImageSet/

4. Run the script:

$ sh rename.sh

Contact

Feedback and questions are welcome, create an Issue for bugs, problems, and potential feature requests.

If you end up using this framework in one of your projects, feel free to let me know, e.g. on Twitter.

Contributions

The list of contributors to this project can be found here.

If you would like to contribute, don't hesitate to open an issue or a pull request.

License

Emojica is released under the Apache License 2.0.

You might also like...
A library for formatting strings on iOS and macOS

Sprinter Introduction What? Why? How? Usage Installation Integration Localization Thread Safety Advanced Usage Introduction What? Sprinter is a librar

A Swifty API for attributed strings

SwiftyAttributes A Swifty API for attributed strings. With SwiftyAttributes, you can create attributed strings like so: let fancyString = "Hello World

Texstyle allows you to format iOS attributed strings easily.
Texstyle allows you to format iOS attributed strings easily.

Texstyle allows you to format attributed strings easily. Features Applying attributes with strong typing and autocompletion Cache for attributes Subst

An easier way to compose attributed strings
An easier way to compose attributed strings

TextAttributes makes it easy to compose attributed strings. let attrs = TextAttributes() .font(name: "HelveticaNeue", size: 16) .foregroundCol

A simple library for building attributed strings, for a more civilized age.

Veneer A simple library for building attributed strings, for a more civilized age. Veneer was created to make creating attributed strings easier to re

Converts Markdown files and strings into NSAttributedStrings with lots of customisation options.
Converts Markdown files and strings into NSAttributedStrings with lots of customisation options.

SwiftyMarkdown 1.0 SwiftyMarkdown converts Markdown files and strings into NSAttributedStrings using sensible defaults and a Swift-style syntax. It us

AttributedString Markdown initializer with custom styling
AttributedString Markdown initializer with custom styling

AttributedString Markdown initializer with custom styling AttributedString in iOS 15 and macOS 12 comes with a Markdown initializer. But: There is no

A Swift framework for parsing, formatting and validating international phone numbers. Inspired by Google's libphonenumber.
A Swift framework for parsing, formatting and validating international phone numbers. Inspired by Google's libphonenumber.

PhoneNumberKit Swift 5.3 framework for parsing, formatting and validating international phone numbers. Inspired by Google's libphonenumber. Features F

OysterKit is a framework that provides a native Swift scanning, lexical analysis, and parsing capabilities. In addition it provides a language that can be used to rapidly define the rules used by OysterKit called STLR

OysterKit A Swift Framework for Tokenizing, Parsing, and Interpreting Languages OysterKit enables native Swift scanning, lexical analysis, and parsing

Comments
  • Some emojis do not work

    Some emojis do not work

    Some of the emojis which can be found here https://getemoji.com in the section "New 2017 Emojis released in June 2017" are not detected at all or are detected as "two emojis" (face plus modifier). furthermore a lot of the people emojis with skin color modifier are detected incorrectly and rendered as two emojis (face plus modifier). How can I fix this? btw why are some huge blocks commented out in the Unicode.swift file?

    I am using twemoji image files as they are supplied in the twemoji repo. I did not change the file names. Tested with iOS 11.

    bug 
    opened by chriswill0w 8
  • How do I use this framework to replace all Emojis in labels with Twemoji?

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

    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!

    question 
    opened by googlercolin 3
  • categories different emoji.

    categories different emoji.

    I want to make emoji category. Like in default iOS keyboard, SMILEYS & PEOPLE, ANIMALS & NATURE, FOOD & DRINKS, ACTIVITY. I have downloaded Image Source from https://github.com/twitter/twemoji. how do I achieve this?

    enhancement 
    opened by Rashesh-Bosamiya 6
Releases(0.9.7)
Owner
Dan
Dan
Croc is a swift emoji string parsing library

Croc is a library for parsing emojis on iOS. It provides a simple and lightweight interface for detecting, generating, categorizing and managing emoji characters, making emoji-powered features an easy task for developers.

Joe Kalash 127 Nov 20, 2022
Effortless emoji-querying in Swift

EmojiKit EmojiKit is a simple emoji-querying framework in Swift. It is used in Paste, an Emoji Search app in the App Store. Installation If you’re usi

Dasmer Singh 93 Nov 12, 2022
Emoji in Swift

Smile ❤️ Support my apps ❤️ Push Hero - pure Swift native macOS application to test push notifications PastePal - Pasteboard, note and shortcut manage

Khoa 478 Dec 30, 2022
Swift emoji string parsing library

Croc is a library for parsing emojis on iOS. It provides a simple and lightweight interface for detecting, generating, categorizing and managing emoji

Joe Kalash 125 Sep 27, 2021
A category on NSString to convert Emoji Cheat Sheet codes to their equivalent Unicode characters

NSString+Emojize A category on NSString to turn codes from Emoji Cheat Sheet into Unicode emoji characters. Getting Started In order to use NSString+E

DIY.org 643 Sep 8, 2022
A searchable emoji dropdown view.

NBEmojiSearchView Integrate a searchable emoji dropdown into your iOS app in just a few lines. To start searching, the user just types a :. Then, the

Neeraj Baid 85 Dec 23, 2022
A simple library that provides standard Unicode emoji support across all platforms

Twitter Emoji (Twemoji) A simple library that provides standard Unicode emoji support across all platforms. Twemoji v13.1 adheres to the Unicode 13.0

Twitter 15k Jan 8, 2023
The world's largest independent emoji font.

The world's largest independent emoji font.

JoyPixels Inc. 337 Dec 24, 2022
🌭 Mustard is a Swift library for tokenizing strings when splitting by whitespace doesn't cut it.

Mustard ?? Mustard is a Swift library for tokenizing strings when splitting by whitespace doesn't cut it. Quick start using character sets Foundation

Mathew Sanders 695 Nov 11, 2022
µframework for Attributed strings.

Attributed µframework for Attributed strings. What is Attributed? Attributed aims to be a drop in replacement to the current version of the NSAttribut

Nicholas Maccharoli 754 Jan 9, 2023