一个用于创建 NSAttributedString 的 DSL。 最初是为了演示函数构造器而创建的,详见此处。
示例
NSAttributedString {
"Hello "
.foregroundColor(.blue)
"World"
.background(.orange)
.underline(.red, style: .thick)
}
您可以通过 Xcode 11 中的 Swift Package Manager 安装它。
前往 File > Swift Packages > Add Package Dependency...
在文本框中粘贴以下内容:https://github.com/carson-katri/AttributedStringBuilder。
可用修饰符
foregroundColor(前景色)background(背景色)underline(下划线)font(字体)shadow(阴影)欢迎添加任何缺失的修饰符。