https://github.com/3sidedcube/attributedtext
Simple wrapper of NSAttributedString
https://github.com/3sidedcube/attributedtext
Last synced: about 1 year ago
JSON representation
Simple wrapper of NSAttributedString
- Host: GitHub
- URL: https://github.com/3sidedcube/attributedtext
- Owner: 3sidedcube
- Created: 2021-06-17T10:51:38.000Z (almost 5 years ago)
- Default Branch: develop
- Last Pushed: 2023-08-01T11:34:43.000Z (almost 3 years ago)
- Last Synced: 2025-01-30T01:22:40.288Z (over 1 year ago)
- Language: Swift
- Size: 82 KB
- Stars: 1
- Watchers: 8
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AttributedText
Simple wrapper of `NSAttributedString`. Importantly, `AttributedText` does not take range into account; it wraps a dictionary of attributes to be set over a *fixed* range.
So, to achieve various attributes at different ranges, it's common to append many `AttributedText`s to an `NSMutableAttributedString`. Or even just using the native `NSAttributedString`.
Currently supported properties which map to `NSAttributedString.Key` (See file `AttributedText+Attributes`):
* `font` (key: `.font`)
* `textColor` (key: `.foregroundColor`)
* `textBackgroundColor` (key: `.backgroundColor`)
* `letterSpacing` (key: `.kern`)
* `underlineStyle` (key: `.underlineStyle`)
* `link` (key: `.link`)
* `textAlignment` (key: `.paragraphStyle` - `.alignment`)
* `lineBreakMode` (key: `.paragraphStyle` - `.lineBreakMode`)
* `lineHeight` (key: `.paragraphStyle` - `.lineHeightMultiple` & `.lineSpacing`)
`text` is a stored property as it doesn't have corresponding `NSAttributedString.Key` like the others.
## Warning:
An `NSAttributedString` with empty text has no attributes (because it has no range).
## Notes:
This framework was previously called `AttributedString` until iOS 15 when Apple released their own [AttributedString](https://developer.apple.com/documentation/foundation/attributedstring). As a result, this framework was renamed to `AttributedText` to prevent naming conflicts.