我正在尝试使用以下代码获取在给定文本容器中显示文本所需的矩形大小:
s = [manager usedRectForTextContainer:container].size;我希望文本在多行中,但它在一行的末尾被截断,并且没有显示下一行上的内容。只有当有几个额外的字符时,才会发生这种情况;在大约60个字符的行中,将有大约10或15个剩余字符应该显示在下一行中,但没有显示。
这会不会是嵌入式的问题呢?也许是文本换行?我真的不确定,因为我对iOS和UI编程都是新手。
编辑:在上面的代码中,manager是一个NSLayoutManager,容器是一个NSTextContainer。
我非常确定这就是问题所在,因为在这个函数调用之后,如果我将s的值更改为我期望的值,我会得到预期的布局,并显示整个字符串。
有关布局管理器的信息如下
<NSLayoutManager: 0xd203f60>
1 containers, text backing has 140 characters
Currently holding 140 glyphs.
Glyph tree contents: 140 characters, 140 glyphs, 1 nodes, 32 node bytes, 384 storage bytes, 416 total bytes, 2.97 bytes per character, 2.97 bytes per glyph
Layout tree contents: 140 characters, 140 glyphs, 62 laid glyphs, 2 laid line fragments, 3 nodes, 96 node bytes, 856 storage bytes, 952 total bytes, 6.80 bytes per character, 6.80 bytes per glyph, 31.00 laid glyphs per laid line fragment, 476.00 bytes per laid line fragment我希望在这种情况下有三行,但看起来只有两行片段,这意味着可能问题出在我的布局管理器中?
发布于 2018-02-23 02:56:25
您正在创建自己的文本容器,但还需要对其进行配置。您需要设置可能想要显示的lineBreakMode和numberOfLines。
在你的情况下我很高兴
textContainer.lineFragmentPadding = 0.0
textContainer.lineBreakMode = label.lineBreakMode
textContainer.maximumNumberOfLines = label.numberOfLineshttps://stackoverflow.com/questions/25148838
复制相似问题