简体   繁体   中英

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!

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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM