If I want formatted text but don't want to use UIWebView, is Core Text my only remaining option?
Asked Answered
H

2

6

If I want formatted text (variations on size, position of certain text elements, etc) but don't want to use UIWebView, is Core Text my only remaining option?

I'm shying away from UIWebView primarily because of problems getting the layout right when switching between the iPad and the iPhone. Rather than doing conditional code and dynamically adjusting the HTML depending on device/orientation, I thought I would go ahead and look at using Core Text.

Suggestions?

Hyps answered 12/2, 2011 at 0:26 Comment(0)
K
3

Perhaps NSAttributedString could help your cause?

An NSAttributedString object manages character strings and associated sets of attributes (for example, font and kerning) that apply to individual characters or ranges of characters in the string. An association of characters and their attributes is called an attributed string. The cluster’s two public classes, NSAttributedString and NSMutableAttributedString, declare the programmatic interface for read-only attributed strings and modifiable attributed strings, respectively.

Knudson answered 4/11, 2012 at 15:19 Comment(1)
Once you have an NSAttributedString, you can display it in a UITextView by setting the text view's attributedText property. This requires iOS 6.Scarrow
F
0

Using only Apple's SDK, yes Core Text is your only other option. I am sure there are third-party implementations, and you could ask that question if you are interested. Apple has a decent example which shows both how to draw text using Core Text and how to handle keyboard input.

Freebooter answered 12/2, 2011 at 2:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.