我在 iOS 中有以下代码:
CFAttributedStringRef attributedString = ...
CTLineRef line = CTLineCreateWithAttributedString(attributedString);
CTLineRef truncatedLine = CTLineCreateTruncatedLine(line, 50.0, kCTLineTruncationEnd, NULL);
CFRange lineRange = CTLineGetStringRange(line);
CFRange truncatedLineRange = CTLineGetStringRange(truncatedLine);
我的 lineRange 与 truncatedLineRange 相同。为什么?文档没有提及这一点。
最佳答案
根据coretext-dev mailing list , this is expected behavior :
The truncated string still covers the original string range, it's just that some glyph(s) have subsumed the truncated characters. Besides, it would be impossible to represent a discontiguous string range as a CFRange in the case of middle truncation.
关于带有来自 CTLineCreateTruncatedLine 的 CTLineRef 的 iOS CoreText CTLineGetStringRange,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5672014/