2

I have a label that I want to set to text with a custom line height. I also want to use dynamic type.

Here's how I'm setting the label:

let attributedString = NSMutableAttributedString(string: "A long string with lots of lines")
attributedString.addAttribute(NSParagraphStyleAttributeName,
                              value: NSMutableParagraphStyle(minimumLineHeight: 28),
                              range: NSRange(location: 0, length: attributedString.length))
myLabel.attributedText = attributedString

If I use the accessibility inspector it won't resize unless I add this line below it:

myLabel.font = UIFont.preferredFont(forTextStyle: .body)

In storyboard the label is set up to use a text-style, be zero lines, word wrap, etc etc... This only happens when using attributed strings.

Is this an apple bug?

Joe Susnick
  • 6,544
  • 5
  • 44
  • 50

1 Answers1

0

because there is no attribute specifying font size when you create that attributed string.

when you set font property you apply that to the range of the entire text: if all attributed text is of the same size why not?

and no, this is not an apple bug

Anton Tropashko
  • 5,486
  • 5
  • 41
  • 66