jowie
jowie

Reputation: 8068

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

Upvotes: 2

Views: 970

Answers (2)

Cocoanetics
Cocoanetics

Reputation: 8247

You might want to look at this Open Source project: https://github.com/Cocoanetics/NSAttributedString-Additions-for-HTML/

Upvotes: 1

cobbal
cobbal

Reputation: 70713

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

Upvotes: 1

Related Questions