Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView with emoticons editing

I am developing xmpp-client app. One of the features is sending smiles and user should have ability to edit its like usuall text. Emoticons editing in Viber App is best example of what i want to implement.

I already tried three ways to solve problem:

  • I create emoticon like usual UIImageView and place it as a subview on UITextView using current caret rect. I use 5 whitespaces as a text placeholder in text view. There are two problems: with placing emoticons on new line when inserting text in the middle(printing whitespace not make caret move to new line); when user placing caret using magnify glass, he can move caret through emoticon(through 5 whitespaces), as delegate method not called during this process.
  • I have tried EGOTextView. There are problems with caret position and resizing when new line should be added. And there are some rendering artifacts when using it one line size.
  • I also have tried using UIWebView. But there were great problems with resizing based on text size and other artifacts with speed of response when becoming first responder.

May be some one could give me advice of really working solution?

like image 428
yariksmirnov Avatar asked Apr 05 '13 18:04

yariksmirnov


Video Answer


1 Answers

I'm not really into rects and ranges mechanism of UITextView/UITextInput, but I try to give you an (untested) advice that maybe could achieve the expected result.

Built-in iOS emojis are simple characters, so we can follow the same path by building a custom font (or extend an existing one). We have two options:

  • If you want to target iOS 6.0 (that has native support for NSAttributedString in UIKit classes), you could try to build a custom font containing all the emoticons you need, and use it inside your NSAttributedString (attributed string can mix different fonts, font sizes, styles and so on).

  • You could do something similar with iOS 5, but since you can't use NSAttributedString inside UITextView (so you are limited to just one font for the entire text) you should use a font that combines together the actual characters and the custom emoticons: so you should extend the font you want to use for typing, by adding all the emoticons to it. I don't know if this could have licenses implications, anyway.

Otherwise, you could always go much more low-level, implementing your own custom textView using CoreText, but I think it would be a hard work.

like image 141
Alessandro Orrù Avatar answered Nov 01 '22 00:11

Alessandro Orrù