Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ArtOfWarfare

macrumors G3
Original poster
Nov 26, 2007
9,672
6,212
Okay, so it seems that the method Apple recommends for displaying rich text on the iPhone is through using a UIWebView. This is fine and all, except I'd like users to be able to intuitively be able to write and edit rich text.

I'm really at a loss for how I'd go about that. Like...

let's say I set up a UIWebView... and in that I had just a string with some text with a few words bolded.

And then I set up a UIButton for bolding.

What exactly should the button do? Somehow I'd need to figure out what text the user has selected in the UIWebView... and somehow I'll need to figure out how to send a method to bold to the UIWebView...

Wait...

am I going to have to learn how to use JavaScript or something? I was really hoping I wouldn't have to learn an entire new language in addition to Obj-C...

If I have to learn JavaScript, can someone point me in the direction of a few lessons.

And if not, can someone suggest a better method.
 
Okay, so it seems that the method Apple recommends for displaying rich text on the iPhone is through using a UIWebView. This is fine and all, except I'd like users to be able to intuitively be able to write and edit rich text.
Yep, DISPLAY. I don't think you'd be well off using UIWebView for text editing, like you want to.

I'm really at a loss for how I'd go about that. Like...

let's say I set up a UIWebView... and in that I had just a string with some text with a few words bolded.

And then I set up a UIButton for bolding.

What exactly should the button do? Somehow I'd need to figure out what text the user has selected in the UIWebView... and somehow I'll need to figure out how to send a method to bold to the UIWebView...

Wait...

am I going to have to learn how to use JavaScript or something? I was really hoping I wouldn't have to learn an entire new language in addition to Obj-C...

If I have to learn JavaScript, can someone point me in the direction of a few lessons.

And if not, can someone suggest a better method.
Never implemented it, but I'd probably go for a UITextView box, where the user enters 'raw' text without formatting. That one does allow you to respond to user input.

Then, if a user selects word #3 in line #2, and clicks 'bold', mark in an internal buffer that the selected letters should all be bold. And then update a uiwebview to DISPLAY said content.

You'd end up with two boxes, one which has the user input, one that has the result of the rich text editing. Not that different from the type of box I'm using to enter this message, though...
 
Yup, rich text is a pain on the iPhone. The platform may be popular, but it's not flawless.

For example, why is there no dark activity spinner? You get to choose between light grey, white, or large white. If you want to show a spinner on a light background, you're out of luck.
 
Rich text editing on iPhone is not an easy task. I would recommend looking at the three twenty code. They have some classes for display of rich text, don't know if they have an editor. I would search for open source javascript code for this purpose. You might find something.

Otherwise, building something like this from scratch is a hard task.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.