An open API service indexing awesome lists of open source software.

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

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.