let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 15
// 字体的行间距
let attributes = [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 14), NSAttributedStringKey.paragraphStyle: paragraphStyle]
self.textView.typingAttributes = attributes.toTypingAttributes()
MARK:- 扩展字典
extension Dictionary where Key == NSAttributedStringKey {
func toTypingAttributes() -> [String: Any] {
var convertedDictionary = [String: Any]()
for (key, value) in self {
convertedDictionary[key.rawValue] = value
}
return convertedDictionary
}
}
SwiftUI 中的文字样式调整
本文介绍如何在SwiftUI中使用NSAttributedStringKey设置字体大小及行间距,并通过扩展字典实现属性转换。
663

被折叠的 条评论
为什么被折叠?



