swift – 添加NSMutableParagraphStyle lineSpacing导致文本不适
发布时间:2020-12-14 04:55:35 所属栏目:百科 来源:网络整理
导读:我创建了一个普通的UILabel,并希望能够为UILabel中的文本添加行间距. 虽然我这样做会影响adjustsFontSizeToFitWidth,它不再适合UILabel. 我用过的一些代码: var userQuestionsAnswer = UILabel(frame: CGRectMake(0,20,20)) userQuestionsAnswer.font = UIF
我创建了一个普通的UILabel,并希望能够为UILabel中的文本添加行间距.
虽然我这样做会影响adjustsFontSizeToFitWidth,它不再适合UILabel. 我用过的一些代码: var userQuestionsAnswer = UILabel(frame: CGRectMake(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) 任何人都可以告诉我为什么这是我以及如何解决它? 解决方法
删除NSMutableParagraphStyle,它将工作. 我不知道为什么但这个属性是打破文本字体大小调整的原因.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |