views:

1868

answers:

2

I need to display text in an iPhone application, something like the way a book is displayed, for example:

Heading

Sub heading

The actual text of the book. Blah. Blah. Blah.


How would I go about doing that? I've found the UITextView and UITextField and UIScrollView objects, but I can't figure out how to use them properly... Any suggestions?

I hope that makes sense...

+12  A: 

You could use HTML in a UIWebView. Or layout a view with multiple UILabels set for particular fonts/sizes/properties. Then use a UITextField for the rest of the unformatted text. In desktop cocoa you can use attributed strings, but I don't think those are available for the iphone.

Ryan Townshend
Not what I was hoping, but after I got you answer I did a bit more research and it looks like UIWebView is about the only reasonable way of doing what I'm looking for, aside from rendering it all myself using CoreGraphics, as Kevin Ballard suggested. (although the idea of rendering it myself does appeal to me, in a strange sort of way :P)
Miquella
+1  A: 

As Ryan said, you can use HTML with a WebView, but if you want to stick to native text drawing, you're going to have to drop down to CoreGraphics and draw all the text by hand. This is a lot of work, but if done right it will be more efficient and have a lower memory footprint than using WebView.

Edit: just took a look at your requirements again, and if only the heading and subheading require style changes, then I would recommend just using separate UILabels for those. You can also call -sizeToFit on the UILabels after assigning their text/font properties so they'll fit their text, which will let you handle wrapped headers/subheaders.

Kevin Ballard