有什么方法可以(轻松)确定格式化 Framesetter 所需的最小宽度?
如果我有一个用像这样的字符串初始化的框架设置器,
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(attrString);
我想找到显示框架中最大字符串的最小宽度。有没有简单的方法可以做到这一点?我可以通过迭代行并运行并从那里计算它来做到这一点,但它似乎有一个方法,因为它会在内部计算它。
我尝试过
CGSize sz = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRangeMake(0,0), NULL, CGSizeMake(1, CGFLOAT_MAX), NULL);
,但它只返回一个恒定的大小,这似乎是单个字形的宽度。
蒂亚
If I have a framesetter that I've initialised with a string like so
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(attrString);
I'd like to find the minimum width to display the largest string in the frame. Is there an easy way to do this? I can do it by iterating over the lines and runs and calculating it from there, but it seems like something that would have a method since it would calculate this internally.
I tried
CGSize sz = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRangeMake(0,0), NULL, CGSizeMake(1, CGFLOAT_MAX), NULL);
but it just returns a constant size which seems to be the width of a single glyph.
tia
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您正在寻找宽度,则应在 CGSizeMake 中传递 CGFLOAT_MAX 作为宽度,以指示宽度不受约束。
一般来说,要查找给定宽度的高度,请传递 CGSizeMake(myWidth, CGFLOAT_MAX),要查找单行文本的宽度,请传递 CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)。
If you're looking for widths, you should pass CGFLOAT_MAX for the width in your CGSizeMake to indicate that width is unconstrained.
Generally speaking, to find a height for a given width, pass CGSizeMake(myWidth, CGFLOAT_MAX), and to find a width for a single line of text, pass CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX).