How to make a custom emoji on iOS 18

Step 1: Understanding Emoji Standards

Before you start designing your custom emojis, it’s essential to understand the standards that govern these little digital icons. Emojis are typically created using Unicode Standard Version (USV), a universal character encoding system that supports over 130,000 characters. These characters include letters, numbers, punctuation, and other symbols, as well as emojis.

Step 2: Creating Custom Emojis with EmojiKit

Creating custom emojis with EmojiKit is a straightforward process that involves the following steps:

a. Adding Dependencies to Your Project

To use EmojiKit in your project, you need to add the library as a dependency in your project’s `Podfile` or `CocoaPodfile`. Here’s an example of how to do this using CocoaPods:

ruby
pod ‘EmojiKit’, :podspec > ‘../node_modules/emojikit.podspec’

Step 2: Creating Custom Emojis with EmojiKit

This will add the EmojiKit library as a dependency in your project and install it automatically when you run `pod install`.

b. Creating Your Custom Emoji

Once you have added the EmojiKit library to your project, you can start creating your custom emojis using the `EmojiKit` class. Here’s an example of how to create a simple custom emoji:

swift
import EmojiKit
let emoji = EmojiKit.createCustomEmoji(name: "My Custom Emoji", image: UIImage(named: "custom_emoji")!, fontSize: 24, scaleFactor: 1.0, animationDuration: 0.5) { [weak self] error in
guard let error = error else { return }
print("Error creating custom emoji: (error.localizedDescription)")
}

In this example, we are creating a custom emoji with the name “My Custom Emoji” and an image file named “custom_emoji”. We are also specifying the font size, scale factor, and animation duration for our custom emoji.

c. Exporting Your Custom Emoji

Once you have created your custom emoji using EmojiKit, you can export it in various formats such as PNG, SVG, or JSON using the `exportAsImage()` method:

swift
let imageData = try! emoji.exportAsImage(size: CGSize(width: 100, height: 100), scale: 2)
UIImage(data: imageData)?.jpegRepresentation(compressionQuality: 1.0) { [weak self] data, error in
guard let data = data else {
print("Error exporting custom emoji: (error?.localizedDescription ?? "Unknown error")")
return
}

// Your code to use the exported custom emoji goes here

}

In this example, we are exporting our custom emoji as a PNG image with a size of 100×100 pixels and a scale factor of 2. We are then converting the exported image data into a JPEG representation that can be used in various contexts.

Step 3: Adding Custom Emojis to Your App

Once you have created and exported your custom emojis using EmojiKit, you can add them to your app by following these steps:

a. Registering Your Custom Emoji in Info.plist

To register your custom emoji in your app, you need to add a new key-value pair to your project’s `Info.plist` file with the following keys:

xml

CFBundleCustomEmojiNames

My Custom Emoji

CFBundleCustomEmojiScalableNames

My Custom Emoji.emojiscaled

In this example, we are registering a custom emoji named “My Custom Emoji” with a scaled version named “My Custom Emoji.emojiscaled”.

b. Using Your Custom Emoji in Your App

Once you have registered your custom emoji in your app’s `Info.plist` file, you can use it in various contexts such as buttons, text fields, or images using the `EmojiKit` class:

swift
import EmojiKit
let emojiButton = UIButton(title: "My Custom Emoji", target: self, action: selector(emojiButtonTapped))
emojiButton.setTitleWith(emoji, for: .normal)
view.addSubview(emojiButton)
@objc func emojiButtonTapped() {
// Your code to handle button tap goes here
}

In this example, we are creating a button with the title “My Custom Emoji” and setting it up to use our custom emoji using the `setTitleWith(emoji, for: .normal)` method. We are also registering a target function for the button’s tap action.

Step 4: Exporting Your Custom Emoji as Assets

To export your custom emoji as assets that can be used in various contexts, you need to create an asset catalog in Xcode and add your custom emoji images to it. You can then use the `EmojiKit` class to reference your custom emojis using their asset catalog names:

swift
import EmojiKit
let emoji = EmojiKit.createCustomEmoji(name: "My Custom Emoji", image: UIImage(named: "custom_emoji")!, fontSize: 24, scaleFactor: 1.0, animationDuration: 0.5) { [weak self] error in
guard let error = error else { return }
print("Error creating custom emoji: (error.localizedDescription)")
}
let imageData = try! emoji.exportAsImage(size: CGSize(width: 100, height: 100), scale: 2)
UIImage(data: imageData)?.jpegRepresentation(compressionQuality: 1.0) { [weak self] data, error in
guard let data = data else {
print("Error exporting custom emoji: (error?.localizedDescription ?? "Unknown error")")
return
}

// Your code to use the exported asset goes here

}

In this example, we are exporting our custom emoji as a PNG image with a size of 100×100 pixels and a scale factor of 2. We are then converting the exported image data into a JPEG representation that can be used in various contexts.

Summary

EmojiKit is a powerful library that provides a simple and consistent interface for creating and using custom emojis in your app. By following the steps outlined above, you can easily create and export your own custom emojis using EmojiKit, and add them to your app’s asset catalog for use in various contexts.