Search code examples
iphoneobjective-cipadcore-text

How can I render different paragraph styles in Core Text?


I'm having a difficult time trying to work out how to build a page using Core Text, where I have multiple paragraphs which follow one another, but in different styles.

In other words, I would like to have a title paragraph, followed by a subtitle paragraph, followed by several body paragraphs. In HTML terms, this would be:

<h1>Some title</h1>
<h2>Some subtitle</h2>
<p>Blah blah...
         ...</p>

I have got as far as creating a CTFramesetter for the title, creating a CTFrame from that, and then drawing it to the context. However I don't understand how to create a new frame which flows on from the previous paragraph. Can anyone help please? Or is there some good online tutorial to help?

Thanks!

:-Joe


Solution

  • The easiest way to do this is to just style your NSAttributedString with the different styles before you create any framesetters.