始终使用sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode获得相同的高度: [英] Always getting the same height using sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:

查看:78
本文介绍了始终使用sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode获得相同的高度:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:返回的CGSize始终具有相同的高度.为什么会这样,并且有办法解决吗?

The CGSize returned by sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode: contains always the same height. Why is that, and is there a way around this?

我想垂直对齐一个字符串,并且除非使用最小字体大小无法容纳在一行上,否则它可能不会被截断.因此,我尝试使用此方法来获取行高,但是无论实际的字体大小是多少,它总是返回57px.

I want to align a string vertically and it may not be truncated, unless it can't fit on a single line using the minimum font size. So I try to use this method to get the line height but it always returns 57px no matter what the actualFontSize is.

有什么想法吗?

推荐答案

我相信您误解了actualFontSize参数.这仅是一个out参数,而不是一个in参数.您为actualFontSize提供什么值无关紧要;如果指针为非NULL,则它将用确定返回大小时使用的字体大小覆盖.返回的实际字体大小将在minFontSize:UIFont实例的大小之间,该实例作为选择器的sizeWithFont:部分的参数提供.

I believe you are misunderstanding the actualFontSize parameter. This is an out parameter only, not an in parameter. It does not matter what value you provide for actualFontSize; if the pointer is non-NULL, then it will be overwritten with the font size used in determining the returned size. The returned actual font size will be between the minFontSize: and the size of the UIFont instance provided as the argument to the sizeWithFont: portion of the selector.

还必须确保将此消息发送到要呈现的字符串.例如,如果您要求的虚拟字符串小于行长,那么您将始终获得相同的值.对于提供的宽度,该虚拟字符串将占用多少高度.

You also must be sure to send this message to the string you intend to render. You would always get the same value, for example, if you are asking a dummy string that's less than a line long how much height it would take for the supplied width.

如果使用调用该方法时使用的实际代码更新问题,那么每个人都会更好地为您提供帮助.

If you update your question with the actual code used in calling the method, everyone would be better able to help you.

这篇关于始终使用sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode获得相同的高度:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆