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)
谁能告诉我这为什么以及我如何解决?
归档时间: |
|
查看次数: |
8102 次 |
最近记录: |