Features
- Comfortable NSAttributedString
- Better autocompletion
- Easy range specification
- Chainable methods
Installation
Carthage
Add the following line to Cartfile:
github "touyu/SwiftyAttributedString"
Create framework:
$ carthage update --platform iOS
CocoaPods
Add the following line to Podfile:
pod 'SwiftyAttributedString'
Enter the following command at the terminal:
$ pod install
Example
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()
Documentation
All Range
"SwiftyAttributedString"
.attr
.font(.systemFont(ofSize: 30)) // All range
.apply()
The Specific Range
"SwiftyAttributedString"
.attr
.range(start: 0, end: 3) {
font(.systemFont(ofSize: 30)) // The specific range
}
.apply()