Thongs 0.9.6

Thongs 0.9.6

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2017年11月
SwiftSwift 版本4.0
SPM支持 SPM

Tomi Koskinen 维护。



Thongs 0.9.6

  • Tomi Koskinen

Thongs 是一个库,用于在 Swift 4 中使 NSAttributedString 创建人性化。

CI Status
Version
License
Platform

用法

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 文件。