How to make Facebook mention like highlighting word in UITextView? - ios

HERE IS SAMPLE IMAGE -->
I'm trying to make text input feature very similar to Facebook's one. The mention that start with # will generate list of my friends name then selecting one will act as something like an object. So deleting the highlighted word will remove whole word in UITextView.
I wonder if that is part of UITextView. Does anyone know how to implement?
Thank you in advance.

I know this is a pretty old question but I've actually made libraries that assist with mentions, when to show the list, does the highlighting etc. It uses attributes on an attributed string to set background.
https://github.com/szweier/SZMentions
https://github.com/szweier/SZMentionsSwift

You'll want to have a look at NSAttributedString. While this class exists in iOS 3.2 or greater, you cannot display it in a UITextView unless you are on iOS 6 or later.

Related

How to store and display styled text in iOS with Swift in a UITextView

I'm a beginner to iOS development and I'm learning how to build something along the lines of a note taking app using Swift, and I want to allow the user to bold, underline, and italicize text. Kind of like how it's done in Apple's Notes app. I'm using a UITextView right now, but that only allows for basic text input.
I want to know how these options are displayed to the user and also how to store this text information. Simply storing the user input as a string doesn't work because it has no way to retain the bold, underlined, and italicized portions (or maybe I'm missing something). Does apple have API for something like this? I have looked into NSAttributedString, but I'm not really sure if that works for this case.
Any help is greatly appreciated, thanks in advance!

How to highlight text in a textView in Swift?

I would like to highlight a part of text in a UITextView like Pages for iOS or Safari for iOS do. I search the documentation but I can't find a way to do it, maybe because I'm a beginner in iOS development and I miss some crucial info. Somebody can help me?
Screenshot of Pages for iOS:
Screenshot of Safari for iOS:
If you only need to highlight a single, contiguous block of text you can set the selection programmatically. Your examples show multiple discontinuous parts however. For that you are going to need to use an attributed string. There is no other system-provided highlighting function. (There might be a third party library that offers this though - you'll have to search.)

Creating an Emoji-Like Keyboard

I am looking to create an emoji keyboard, which works similar to the native one on iPhone.
Currently all apps that provide a keyboard, do not let you insert an emoji inline with the text.. rather they provide you the ability to 'paste' it in like an image.
In addition to this, if an emoji is sent to a user that doesnt have the app installed, will they see the 'emoji' or will it display as a bunch of random characters?
I was hoping someone could point me in the right direction, as I cannot find the detail I am looking for.
Thanks
As for creating custom keyboards, you should get started by reading Apple's official documentation on the subject.
To answer your question about displaying Emoji: Any platform that supports Emoji will see them as an Emoji. A good source to see which platforms support it is CanIEmoji.com. Any other platforms will likely display it as an empty square, since it is not a supported character.
Any custom emoji keyboard you create will show up like a picture attachment, iOS especially doesn't allow custom inline emojis. Check out these two articles they might help with even more info:
https://www.bluecloudsolutions.com/blog/emoji-apps/
https://medium.com/#mantia/so-you-want-to-build-an-emoji-keyboard-26450ba5136a

Keep Entire Text From Changing

I have been trying to make a font type app for iOS in Xcode. It alters the normal text into emoji and unicode type letters and there are several different font variations to choose from. Right now, every time a new font is chosen, it changes the whole text field to that one selected font. But I'm trying to make it so that it doesn't effect the whole text field when a new font is selected, only the words that will be typed from that point on. I would appreciate if someone could help me with the code that would allow this. I would think its very easy but just not sure what to do.
An example app that does what my app does: https://itunes.apple.com/us/app/textizer-fonts-fun-looking/id563544682?mt=8
An example app that does what i want my app to do: https://itunes.apple.com/us/app/better-fonts-free-cool-new/id735011588?mt=8
Thanks in advance!
***Edit: My question is different because others are referring to actual fonts in the code and program. My situation is totally different. This is a special kind of app and the "font" is actually unicode symbols which is all the same language to a computer. So im actually just trying to make xcode and the app change without clearing the last symbol effect on the keyboard. It just like normal typing, and would actually be normal if it didn't change after a new one is selected. Not sure why the whole text box changes to the font that is selected, but i would think that its really easy to just add a line of code that doesn't make it change all the letters. If you just checked my links you would easily be able to see. Thanks again and sorry for the confusion. All help and code is appreciated.

How do I go about building a native iOS rich text editor?

We want a native rich text editor because we are trying to stay away from using Javascript and webviews for this solution.
We've tried many things so far, and we're left with quite a few obstacles that we just can't get around. Let me break it down into questions that I hope you can answer.
I have a UIButton, that says "B" on it, and I want to put it into the 'selected' state when a user sets 'Bold' from using the TextView's long-press gesture on a selection. How do I register for this state change? I tried adding an observer on the textView.attributedText, but it doesn't seem they are changing that dictionary, but instead are updating it. NSDictionary has no way, as far as I know, to add observers on the dictionary's keys. So I'm stuck with noticing this change.
Regarding number 1, I also tried setting the textView's inputDelegate and it seems that the method - (void)textDidChange:(id )textInput never gets called. :( Docs says is should. What did I do wrong?
How do I update the attributedText weight when I hit my bold italic or underline button.
How do I convert my attributed text into HTML?
I saw a few neat libraries for number 4, but I'm still curious what you'd come up with. (Broadens my options). But, I can't really work on number 4 until I figure out how to do the previous 3.
This editor will also need hyperlinks, bulleted lists, and numbered lists, more things I imagine I'll struggle through, but if you could answer the 4 questions above, that will keep me held over for a while. :)
Thanks!
Here is a link to an iOS rich text editor I've been working on.
https://github.com/aryaxt/iOS-Rich-Text-Editor
There is still a lot of work that has to be done, but the basic features are there.
The Apple sample application called 'TextEdit' does much of what you've described and, if not that, would be a very good starting point. Find the sample code with a search in the Organizer.
There is a commercial editor based on the DTCoreText library. I've used that library but not the rich text editor. Look at the Cocoanetics web site. It's not cheap but will save you a ton of work.

Resources