Miquella
Miquella

Reputation: 1084

Display formatted text on the iPhone

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

Upvotes: 2

Views: 4151

Answers (2)

Lily Ballard
Lily Ballard

Reputation: 185701

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.

Upvotes: 1

Ryan Townshend
Ryan Townshend

Reputation: 2394

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.

Upvotes: 13

Related Questions