简体   繁体   English

NSRange的多个CTLine

[英]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)? 是否有办法找出NSAttributedString中某个字符的NSRange是否在多行上(CTLine)?

What I'm doing is setting the NSAttributedString, then creating the framesetter with that string. 我正在做的是设置NSAttributedString,然后使用该字符串创建框架设置器。 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: 从制版机获取CTFrameRef之后,您需要调用:

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: 如果您需要知道一行(在本例中为第0行)中字符(从原始字符串开始)的确切范围,请使用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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