NSAttributedString size calculation returns different results with .usesFontLeading option

Viewed 127

TLDR; I found out that .usesFontLeading return the different result in iOS 13, but I want to know why ?


I have a bug in iOS 13 that my app shows the wrong text height. This bug does not happen in iOS 12.

I have the code to calculate the multi-line height of NSAttributedString.

I found that with different options, one has font leading, another one does not. The code returns different results.

let height_with_font_leading = text.boundingRect(with: constraintSize,
                                                 options: [.usesLineFragmentOrigin, .usesFontLeading],
                                                 context: nil).height

let height_with_no_font_leading = text.boundingRect(with: constraintSize,
                                                    options: [.usesLineFragmentOrigin],
                                                    context: nil).height

The height from the calculations are shown as images below.

with_font_leadingwithout_font_leading

As you see, the height without .usesFontLeading is correct, because the label can show full text without truncation.

  1. What is the purpose of .usesFontLeading ?
  2. When should I use it ?

Here is the full snippet of my code:

https://gist.github.com/nRewik/7760ac31f107642c70eb9e659862ac3b

0 Answers
Related