ios - 如何更改 UILabel swift 中文本的行距

标签 ios swift

我查看了堆栈中的解决方案,但它们对我没有帮助。以下是我尝试更改 UILabel 中文本的行距。请有人建议。我看不出对我的行距有影响。

 let myText = abstractText.text!
 let myParagraphStyle = NSMutableParagraphStyle()
 myParagraphStyle.lineSpacing = 5

 let myNsAttrStringObject = NSAttributedString.init(string: myText, attributes: ["paragraphStyle":myParagraphStyle])
 abstractText.attributedText = myNsAttrStringObject

最佳答案

这样你的属性键是不正确的,你可以使用 objective-c key NSParagraphStyleAttributeName 或者 swift 4 key NSAttributedStringKey.paragraphStyle:

let myNsAttrStringObject = NSAttributedString.init(string: myText, attributes: [NSParagraphStyleAttributeName: myParagraphStyle])

关于ios - 如何更改 UILabel swift 中文本的行距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47120673/

相关文章:

ios - 详细信息披露按钮和披露指示器有什么区别?

ios - Realm :按子对象中的属性排序

php - swift 3.0 中的播放器 ID 格式问题

ios - 在 View 已经可见时更改 uitabbar 图标

html - iOS7/Mavericks Safari 奇怪的元素边框行为

iOS 7 UISearchDisplayController 问题

ios - 越狱设备上的调试服务器

ios - 是否可以在通话过程中从 iOS 应用程序向当前调用者发送短信?

ios - 如何将用户默认的一个 TextView 中的数据保存到另一个 TextView 而不删除以前的数据?

ios - swift : get all installed application and open specific one