NSParagraphStyle lineSpacing unexpected behavior

I have an attributed string in a UITextView and I'm trying to use a paragraph style to set line spacing:


let paragraphStyle = NSMutableParagraphStyle()

paragraphStyle.lineSpacing = 11.0

let attributes: [NSAttributedStringKey: Any] = [

.font: myFont

.paragraphStyle: paragraphStyle

]

let str = NSMutableAttributedString(string: string as String, attributes: attributes)


I find that lineSpacing has no effect unless I also set paragraphStyle.maximumLineHeight.


paragraphStyle.maximumLineHeight = 12.0

I guess that's ok, but the problem is handling dynamic type. The fixed value for maximumLineHeight doesn't work when type size changes. In iOS 11, I can use UIFontMetrics to scale these values, but what do I do pre-iOS 11?

Am I missing something? Is there a more straightforward way to control line spacing?

NSParagraphStyle lineSpacing unexpected behavior
 
 
Q