带有来自 CTLineCreateTruncatedLine 的 CTLineRef 的 iOS CoreText CTLineGetStringRange

标签 ios core-text

我在 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/

相关文章:

iOS - 如何在 PDF 文档顶部添加文本?

android - Stella SDK 转安卓

ios - 如果我们点击背景中的任何地方,除了快速点击 popView 之外,如何删除 popView

ios - iOS 的类似卡拉 OK 的进度突出显示

ios6 - libMobileGestalt copySystemVersionDictionaryValue : Could not lookup ReleaseType from system version dictionary

ios - Core Text 将所有系统字体加载到驻留内存中

iphone - 获取 UITextView 键盘的 y 值

ios - 从 didFinishLaunchingWithOptions 打开 ViewController

ios - iOS 上来自国家/地区代码的电话号码格式

macos - 在 NSAttributedString 的一部分周围绘制边框