Gutenberg is tiny library that can generate NSAttributedString from given string and replace registered characters with images (emoji).
Import Gutenberg
import Gutenberg
Create as many emoji as you want
let emoji1 = Emoji(code: "*angry*", image: UIImage(named: "angry")!)
let emoji2 = Emoji(code: "*grin*", image: UIImage(named: "grin")!)
Set default height and offset based on your preferred font so the emojis are aligned nicely (optional)
Gutenberg.setDefaultHeight(self.textLabel.font.lineHeight)
Gutenberg.setDefaultYOffset(self.textLabel.font.descender)
And register them
Gutenberg.registerEmoji(emoji1, emoji2)
Then create label
@IBOutlet weak var textLabel: GutenbergLabel!
and set the text
self.textLabel.text = "Hey! *grin* Where are you? *angry*"
And that's all. If you don't want to use our GuttenbergLabel (it's just UILabel subclass), there is also an extension for UILabel with method gtb_text:
.
self.textLabel.gtb_text = "Hey! *grin* Where are you? *angry*"
It's just cosmetics :-)
There are no special requirements. Gutenberg takes advantage of the NSTextAttachment class to replace the occurences of registered strings with them.
Gutenberg is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "Gutenberg"
Aleš Kocur, [email protected]
Gutenberg is available under the MIT license. See the LICENSE file for more info.