Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YYTextLayout计算的高度不准确 #900

Open
LucioLee opened this issue Sep 5, 2019 · 3 comments
Open

YYTextLayout计算的高度不准确 #900

LucioLee opened this issue Sep 5, 2019 · 3 comments

Comments

@LucioLee
Copy link

LucioLee commented Sep 5, 2019

比较了NSAttributedString自带的文字高度计算方法

open func boundingRect(with size: CGSize, options: NSStringDrawingOptions = [], context: NSStringDrawingContext?) -> CGRect

和YYTextLayout的文字高度计算方法

  let layout = YYTextLayout(container: textContainer, text: attributedTitle)!
  let height = layout.textBoundingRect

还有TextKit的文字高度计算方法

发现只有NSAttributedString自带的文字高度计算方法返回的高度是最准确的

@LatteCat
Copy link

是不是使用了非系统字体?我发现在 iOS 13 下使用了非系统字体的话,YYText 计算的高度就不准确

@LucioLee
Copy link
Author

LucioLee commented Oct 15, 2019

是不是使用了非系统字体?我发现在 iOS 13 下使用了非系统字体的话,YYText 计算的高度就不准确

是的,我们APP都是自定义字体,Core Text 、TextKit和YYText算出来的高度都不准确,YYText底层就是基于Core Text计算的吧!

@LatteCat
Copy link

跟你一样的,我们也使用了自定义字体,目前我使用的是 TTTAttributeLabel 来做展示。快要上线了,我们测试发现,iOS 13 下,有空白行的文字高度计算有问题,但是使用系统提供的 boundingRect 方法就可以计算出来。
目前我的解决方法是:iOS 13 下,使用系统提供的 boundingRect 计算,然后加一个常量值(这个值就需要你自己去慢慢试了)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants