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.
textViewDidChange(_:)
Podfile
:target '...' do
pod 'Emojica'
end
$ cd /Path/To/Your/Project/ && pod install
Cartfile
:github "xoudini/emojica"
$ cd /Path/To/Your/Project/ && carthage update
Open your project use Xcode.
Click File
-> Add Packages
, enter repository url.
https://github.com/xoudini/emojica
Emojica.xcodeproj
into your project
hierarchy in Xcode.Emojica.frameworkiOS
and finish by pressing Add.If Xcode gives you a
No such module 'Emojica'
compiler error at yourimport
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.
import Emojica
let emojica = Emojica()
// Creates an instance with a font.
let emojica = Emojica(font: UIFont.systemFont(ofSize: 17.0))
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.
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.
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.
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.
let sample: String = "Sample text ๐"
let converted: NSAttributedString = emojica.convert(string: sample)
NOTE: The instance must have
revertible
set totrue
.
let reverted: String = emojica.revert(attributedString: converted)
let textView = UITextView()
...
let flag: String = "๐ซ๐ฎ "
textView.attributedText = emojica.convert(string: flag)
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)
}
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 |
1. U+2640, U+2642 and U+2695 and sequences containing these characters are unsupported.NOTE: The newest EmojiOne and Noto sets haven't been checked in a while.
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.
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:
rename.sh
into the folder containing your image set.$ cd /Path/To/Your/ImageSet/
$ sh rename.sh
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.
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.
Emojica is released under the Apache License 2.0.
link |
Stars: 103 |
Last commit: 4 weeks ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics