NSAttributedStringBuilder
上下文
NSAttributedStringBuilder 是一个利用函数构建器利用函数构建器实现语法糖,从而直观地组合属性的 Swift 微框架。
不再是编写
let attributedString = NSMutableAttributedString(string: "Hello", attributes: [.font: UIFont.systemFont(ofSize: 24), .foregroundColor: UIColor.red])
attributedString(NSAttributedString(string: " world!", attributes: [.font: UIFont.systemFont(ofSize: 20), .foregroundColor: UIColor.orange]))
您现在可以写
let attributedString = NSAttributedString.composing {
NSAttributedString(string: "Hello", attributes: [.font: UIFont.systemFont(ofSize: 24), .foregroundColor: UIColor.red])
NSAttributedString(string: " world!", attributes: [.font: UIFont.systemFont(ofSize: 20), .foregroundColor: UIColor.orange])
}
要求
Xcode 11+ & Swift 5.1
安装
CocoaPods
将以下内容添加到您的 Podfile
中:
pod "NSAttributedStringBuilder"
Carthage
请将以下内容添加到您的Cartfile
github "vincent-pradeilles/NSAttributedStringBuilder"
作者
- Twitter: @v_pradeilles