TextAttributes is a Swift library that simplifies the creation and modification of NSAttributedStrings. Its intuitive, strongly typed API enables easy creation of rich text with attributes such as bold, italic, underlined, colored text and more.
- Simple, intuitive, and strongly typed API for building complex text attributes
- Easy application of text attributes such as font, color, kerning, and more
- Customizable paragraph styles, including indentation, line spacing, and alignment
- iOS 12.0+
- Swift 5.0+
You can use CocoaPods to install TextAttributes
by adding it to your Podfile
:
platform :ios, '12.0'
use_frameworks!
pod 'TextAttributes', :git => '[email protected]:joeypatino/textattributes.git'
Then, run the pod install
command to install the library.
Here's are some examples of how to use TextAttributes:
import TextAttributes
let label = UILabel()
let string = "hello world"
let attributedString = string.attributed().mutable
attributedString.addAttribute(.foregroundColor(.red))
attributedString.addAttribute(.font(.boldSystemFont(ofSize: 32.0)))
attributedString.addAttribute(.kern(2.0))
label.attributedText = attributedString
import TextAttributes
let label = UILabel()
let string = "hello world"
let attrs = [TextAttribute.foregroundColor(.red), .font(.boldSystemFont(ofSize: 32.0)), .kern(2.0)]
attributedString.addAttributes(attrs, toOccurencesOfString: "hello")
label.attributedText = attributedString
import TextAttributes
let label = UILabel()
let string = "hello world"
let attributedString = string.attributed().mutable
attributedString.addAttribute(.foregroundColor(.red))
attributedString.addAttribute(.font(.boldSystemFont(ofSize: 32.0)))
attributedString.removeAttribute(.foregroundColor, fromOccurencesOfString: "o wor")
label.attributedText = attributedString
Contributions to TextAttributes are welcome! If you find a bug or would like to make an improvement, please report it on the project's GitHub page at https://github.com/joeypatino/textattributes.
Joey Patino – @nsinvalidarg – [email protected]
TextAttributes is released under the MIT License. See the LICENSE file for details.