https://github.com/bannzai/stringattribute
StringAttribute is simple to write about NSAttributedString
https://github.com/bannzai/stringattribute
Last synced: 10 months ago
JSON representation
StringAttribute is simple to write about NSAttributedString
- Host: GitHub
- URL: https://github.com/bannzai/stringattribute
- Owner: bannzai
- License: mit
- Created: 2017-07-11T03:56:14.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2020-12-10T11:19:49.000Z (over 5 years ago)
- Last Synced: 2025-07-30T13:49:38.511Z (11 months ago)
- Language: Swift
- Homepage:
- Size: 2.25 MB
- Stars: 46
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# StringAttribute
`StringAttribute` is simple to write about NSAttributedString.

# Usage
You can write like the one below.
- Initialize attributed string
```swift
"Hello, world".attributed() // NSAttributedString
```
- Attach attributes with method chain
```swift
label.attributedText = "Hello, world".attributed()
.apply(with: .foregroundColor(.white)) // All text to be white color
.apply(with: .foregroundColor(.blue), in: 0..<5) // "Hello" to be blue color
.apply(with: [.font(UIFont.boldSystemFont(ofSize: 20)), .foregroundColor(.red)], for: "world") // "world" is to be Bold font and red color
```
- Attach paragraph style with method chain
```swift
label.attributedText = "Hello, \nworld".attributed()
.apply(with: .paragraph(.complex([.alignment(.center), .lineSpacing(20)]))) // All line text alignment is center and line space is 20.
.apply(with: .paragraph(.firstLineHeadIndent(20)), for: "world") // Containing "world", the head indent of line is 20px
```
# TODO
- [ ] Write test
- [x] Add demo project
- [ ] Add playground sample
- [x] CocoaPods
- [ ] Carthage
# License
**StringAttribute** is available under the **MIT** license. See the LICENSE file for more info.