UITextView with emoticon editing

I am developing an xmpp-client application. One of the features is sending smiles, and the user should be able to edit it like plain text. Emoticon editing in the Viber App is the best example of what I want to implement.

I already tried three ways to solve the problem:

  • I create an emoticon like a regular UIImageView, and put it as a subitem in a UITextView using the current curt rect. I use 5 spaces as a text placeholder in a text view. There are two problems: placing emoticons on a new line when inserting text in the middle (a blank space will not lead to the carriage moving to a new line); when the user places the carriage with a magnifying glass, he can move the carriage through the emoticon (after 5 spaces), since the delegate method is not called during this process.
  • I tried EGOTextView . There are problems with the carriage position and resizing when adding a new line. And there are some rendering artifacts when using the same row size.
  • I also tried using UIWebView. But there were big problems with resizing based on the size of the text and other artifacts with a response speed when you became the first responder.

Can someone give me advice on a really working solution?

+7
source share
1 answer

I am not very versed in the UTextView / UITextInput mechanisms, but I am trying to give you (unverified) advice that may possibly achieve the expected result.

Embedded iOS emojis are simple characters, so we can follow the same path, creating our own font (or expanding an existing one). We have two options:

  • If you want to target iOS 6.0 (which has built-in support for NSAttributedString in NSAttributedString classes), you can try to create your own font containing all the emoticons you need and use it inside NSAttributedString (the attribute string can mix different fonts, font sizes , styles, etc.).

  • You can do something similar with iOS 5 , but since you cannot use NSAttributedString inside a UITextView (so you are limited to one font for all the text) you should use a font that combines the actual characters and custom emoticons: so you have to expand the font, which you want to use for input, adding to it all the emoticons. I do not know if this may have consequences for licenses.

Otherwise, you can always go much lower level by embedding your own text file using CoreText , but I think it will be hard work.

+2
source

All Articles