测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可 | MIT |
发布日期最后发布版本 | 2017年9月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Dmitry Frishbuter 维护。
TriBulus 提供了一种非常便捷的创建富文本字符串的方式。它是一个基于自定义 Attributes
类和使用友好的链式语法构建的框架。
将 Sources
文件夹从 最新版本 中拖到您的项目中。
您可以使用以下代码以所需的属性初始化富文本字符串
let attributedString = NSAttributedString(string: testString) {
$0.font = .systemFont(ofSize: 10, weight: UIFontWeightBold)
$0.backgroundColor = .green
$0.color = .black
$0.baselineOffset = 14.0
}
TriBulus 还允许向现有的可变富文本字符串追加。
下面是追加新的富文本字符串的代码示例
let attributedString = NSMutableAttributedString(string: "Foo")
attributedString
.append(string: " Bar") {
$0.color = .red
}
.append(string: " Baz") {
$0.direction = .horizontal
}
以同样的方式,您也可以追加任何图片
let attributedString = NSMutableAttributedString(string: "Foo")
attributedString.append(image: UIImage(named: "Bar"),
bounds: CGRect(x: 0, y: 0, width: 40, height: 40))
此外,TriBulus 允许您在任意位置插入新生成的富文本字符串
let attributedString = NSMutableAttributedString(string: "Foo Baz")
attributedString
.insert(string: "Bar", at: 4) {
$0.textEffect = .letterpress
}
或插入图片
attributedString.insert(image: UIImage(named: "Bar"),
bounds: CGRect(x: 0, y: 0, width: 40, height: 40),
at: 0)
而不是创建 UIFontDescriptorSymbolicTraits
,您可以直接使用 Attributes
对象的属性来设置 加粗 和 斜体 特性
let attributedString = NSAttributedString(string: testString) {
$0.bold = true
$0.italic = true
}
Dmitry Frishbuter, [email protected]
Tribulus 在 MIT 许可下提供。有关更多信息,请参阅 LICENSE 文件。