Matt W.
Matt W.

Reputation: 956

Multiple CTLine's for NSRange

I'm new to core text. Is there a way to find out if a certain NSRange of characters in an NSAttributedString is on multiple lines (CTLine)?

What I'm doing is setting the NSAttributedString, then creating the framesetter with that string. The string can be varying lengths, and I'm wondering how to find if a range (ie a phrase) is on multiple lines. Because it is a varying length string, I'd rather not set each individual line if I can.

Thanks!

Upvotes: 0

Views: 431

Answers (1)

lnafziger
lnafziger

Reputation: 25740

So you need to use the following functions in order to get the line's:

Once you get the CTFrameRef from the framesetter, you need to call:

CFArrayRef lines = CTFrameGetLines (frame);

then to see how many lines there are, count the lines in the array:

CFIndex numLines = CFArrayGetCount(lines);

If you need to know the exact range of characters (from the original string) in a line (line 0 in this case), use:

CFRange range = CTLineGetStringRange(CFArrayGetValueAtIndex( lines, 0));

Upvotes: 1

Related Questions