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

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.

Related

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.)

Customising the Decimal pad in my app

Swift...
So I've got an existing app and I'm working on its appearance. The current task is customising the decimal pad that pops up when the user hits a textField.
I've looked around on how to make it but it always seems that you have to go into the iPhone/ipad settings and add the custom keyboard.
eg. This StackOverFlow Question
and they all seem to point to this same tutorial..
iOS 8: Creating a Custom Keyboard
My problem is that I don't want the user to have to go into settings.
So the question is....IS THIS POSSIBLE?
The following pic is what I want to use. I have made this in an XIB file through adding a target keyboard which makes the new folder with KeyboardViewController.swift , info.plist and NumPad.xib. Though i think I'm on the wrong track, can someone point me the right way please.
Also anyone know the exact dimensions this view should be.. assuming what I'm asking is in fact possible. Let me know if I'm not being clear enough!
NumPad.xib(pic)
Many many thanks,
Steve
SOLUTION: Thanks to Andrea for correcting my search keywords. It led me to this Stack Question which hopefully sends some others to the correct end of the internet that have mistakes custom keyboard with custom input views!
Sure it is possible without going into settings, but they are called custom input views.
You should look into inputViews here what Apple says about them Custom views for data input.
Basically when the user press a text field instead of loading the usual keyboard it loads an inputView that you specify, pay attention that custom keyboard term is misleading. If you google for tutorial you'll find most probably link like the ones that you found.
For a practical example check this tutorial or this, is a little bit old, but the principle are still the same

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.

Is there an alternative to UIWebView for dynamically displaying formatted text?

Working on an app that needs to take a large amount of text, paginate it based on user selected font size, etc., and display it with styles. Getting UIWebView to paginate a document has proven extremely troublesome. I have seen a wrapper for Core Text that apparently, takes care of layout, but my understanding is that core text cannot be selected.
Looking to do something similar to the books available through the app "eReader", or the app made for the book "The Adderall Diaries". Anyone know how they accomplished this? I had assumed it was UIWebView.
Normally I'd say using UILabel with NSAttributedString, however since you also need to select text, things get a bit more complicated. Head over to the Apple Dev Forums and check out the changes in iOS 6 to attributed strings (it's under NDA).

Which text rendering framework should I use?

I'm currently scoping out a project for the iPad which is rather text and font heavy. There are many pages of styled text, which also need custom fonts. I have toyed with the idea of simply rendering PDF or PNG files on-screen, but I think we need to be able to dynamically repaginate the text.
We've used UIWebView in a previous project quite successfully, however there are a few things I don't like about it... Firstly, you have to hide all the silly drop shadow elements to stop them showing when the user scrolls beyond the bounds, and we had to add some JavaScript to find out actually when a page had fully loaded. Overall, the experience seemed a bit clunky, as well as worrying if the project could potentially break if Apple decided to update the subviews...
The other thing we've been looking at is Core Text, which looks very powerful. The only worry with this is that it appears to be a rather steep learning curve for us since we've mainly been working in UIKit (with a bit of Core Graphics). I couldn't even work out how to change the size of the font after a morning's work.
Are there any other alternatives*? Should I stick with Core Text? Is there any way of using UITextView with multiple fonts and styles?
Thanks!
:-Joe
EDIT: *by alternatives, I am really looking for built-in iPhone SDK alternatives only please... I would rather not mess with third party frameworks because I don't have the time... Thanks :)
You could use Pango, which uses CoreText when on iOS.

Resources