测试已测试 | ✓ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布最后发布 | 2017年11月 |
SwiftSwift 版本 | 4.0 |
SPM支持 SPM | ✗ |
由 Tomi Koskinen 维护。
Thongs 是一个库,用于在 Swift 4 中使 NSAttributedString 创建人性化。
import Thongs
// Create a formatter by combining different attributes, such as font, color, kerning...
// then style the string with the formatter
let red = Thongs.color(UIColor(red: 231/255, green: 76/255, blue: 60/255, alpha: 1))
let large = Thongs.font(UIFont(name: "Avenir-Black", size: 28)!)
let kerning = Thongs.kerning(1.4)
let titleFormatter = red <*> large <*> kerning
titleLabel.attributedText = titleFormatter(Thongs.string("This thing right here"))
// combine string attributes with the <*> operator
// combine differently styled parts using the <+> operator
let bodyTextFontStyle1 = Thongs.font(UIFont(name: "Baskerville-SemiBoldItalic", size: 24)!)
let bodyTextFontStyle2 = Thongs.font(UIFont(name: "BradleyHandITCTT-Bold", size: 16)!)
let formatter1 = bodyTextFontStyle1 <*> Thongs.color(UIColor(red: 46/255, green: 204/255, blue: 113/255, alpha: 1))
let formatter2 = bodyTextFontStyle2 <*> Thongs.color(UIColor(red: 34/255, green: 167/255, blue: 240/255, alpha: 1))
let formatter3 = bodyTextFontStyle1 <*> Thongs.color(UIColor(red: 232/255, green: 126/255, blue: 4/255, alpha: 1))
let formatter4 = bodyTextFontStyle2 <*> Thongs.color(UIColor(red: 191/255, green: 85/255, blue: 236/255, alpha: 1))
let formatter5 = bodyTextFontStyle1 <*> Thongs.color(UIColor(red: 245/255, green: 215/255, blue: 110/255, alpha: 1))
let formattedLine = Thongs.font(UIFont(name: "Courier", size: 16)!) <*> Thongs.color(UIColor(red: 103/255, green: 65/255, blue: 114/255, alpha: 1)) ~~> "Check it out\n"
textBox.attributedText = formatter1 ~~> "Is lettin all the ladies know\n" <+>
formatter2 ~~> "What guys talk about\n" <+>
formatter3 ~~> "You know\n" <+>
formatter4 ~~> "The finer things in life\n" <+>
formatter5 ~~> "Hahaha\n" <+>
formattedLine
支持颜色、字体、间距、下划线和删除线,但易于扩展。欢迎 Pull requests。
Thongs 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod "Thongs"
Tomi Koskinen, [email protected]
Thongs 根据MIT许可证提供。有关更多信息,请参阅 LICENSE 文件。