添加NSMutableParagraphStyle lineSpacing导致文本不适合UILabel

Hen*_*own 6 uilabel swift nsparagraphstyle

我已经创建了一个普通的UILabel,并且希望能够为在UILabel中添加文本添加行距。

虽然在执行此操作时会影响adjustsFontSizeToFitWidth,并且不再适合UILabel。

我使用了一些代码:

        var userQuestionsAnswer = UILabel(frame: CGRectMake(0, 0, 20, 20))
        userQuestionsAnswer.font = UIFont(name: Font.GothamBlack, size: 15)
        userQuestionsAnswer.numberOfLines = 0
        userQuestionsAnswer.adjustsFontSizeToFitWidth = true

        var style = NSMutableParagraphStyle()
        style.lineSpacing = view.frame.size.height * 0.021
        style.alignment = NSTextAlignment.Center
        let attributes = [NSParagraphStyleAttributeName : style]
        var answerText = "This is the answer"

        self.userQuestionsAnswer.attributedText = NSAttributedString(string: answerText!, attributes:attributes)
Run Code Online (Sandbox Code Playgroud)

谁能告诉我这为什么以及我如何解决?

Tom*_*yer 0

删除它就NSMutableParagraphStyle可以工作了。我不知道为什么,但这个属性是破坏文本字体大小调整的原因。