Skip to content
This repository was archived by the owner on Feb 17, 2021. It is now read-only.
This repository was archived by the owner on Feb 17, 2021. It is now read-only.

Wrong LabelLayout height when using attributed string with kern and line height #184

Description

@plamenterziev

For some reasons setting both kern and line height of an attributed string makes boundingRect to return wrong height if the string can fit only one line.

  let paragraphStyle = NSMutableParagraphStyle()
  paragraphStyle.lineSpacing = 100
  let text = NSMutableAttributedString(
       string: "test",
       attributes: [NSAttributedStringKey.paragraphStyle : paragraphStyle,
                           NSAttributedStringKey.kern : 0.1,
                           NSAttributedStringKey.font : UIFont.systemFont(ofSize: 17)])
  let size = text.boundingRect(with: CGSize(width: 1000, height: 1000),
                                                   options: [.usesLineFragmentOrigin], 
                                                   context: nil).size

Here the size is (29.59384765625, 120.287109375) which seems fine for width but the height is wrong (maybe is the real height + the line height).

If the text goes multilines then boundingRect returns correct height.

Also removing the kern attribute or setting it to 0 also fixes the problem.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions