- Comfortable NSAttributedString
- Better autocompletion
- Easy range specification
- Chainable methods
- Customizable
Add the following line to Cartfile:
github "touyu/SwiftyAttributedString"
Create framework:
$ carthage update --platform iOS
Add the following line to Podfile:
pod 'SwiftyAttributedString'
Enter the following command at the terminal:
$ pod install
textView.attributedText = "SwiftyAttributedString"
.attr
.font(.systemFont(ofSize: 30))
.range(of: "Swifty") {
$0.foregroundColor(.blue)
}
.range(of: "Attributed") {
$0.foregroundColor(.red)
$0.underlineStyle(.single)
}
.range(of: "String") {
$0.foregroundColor(.orange)
$0.font(.boldSystemFont(ofSize: 30))
}
.apply()
"SwiftyAttributedString"
.attr
.font(.systemFont(ofSize: 30)) // All range
.apply()
"SwiftyAttributedString"
.attr
.range(start: 0, end: 3) {
$0.font(.systemFont(ofSize: 30)) // The specific range
}
.apply()
"SwiftyAttributedString"
.attr
.customize()
.apply()
extension SwiftyAttributedString {
func customize() -> SwiftyAttributedString {
return font(.systemFont(ofSize: 30))
.range(of: "Swifty") {
$0.foregroundColor(.blue)
}
.range(of: "Attributed") {
$0.foregroundColor(.red)
$0.underlineStyle(.single)
}
.range(of: "String") {
$0.foregroundColor(.orange)
$0.font(.boldSystemFont(ofSize: 30))
}
}
}