Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/geri-borbas/ios.blog.uilabel_typography_extensions
Set UILabel line height, letter spacing (and more). 📐
https://github.com/geri-borbas/ios.blog.uilabel_typography_extensions
extension ios letter-spacing line-height nsattributedstring nskeyvalueobservation strikethrough swift typography uikit uilabel underline
Last synced: about 1 month ago
JSON representation
Set UILabel line height, letter spacing (and more). 📐
- Host: GitHub
- URL: https://github.com/geri-borbas/ios.blog.uilabel_typography_extensions
- Owner: Geri-Borbas
- Created: 2020-12-22T11:13:16.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-05-15T18:24:52.000Z (over 2 years ago)
- Last Synced: 2023-08-01T04:27:18.631Z (over 1 year ago)
- Topics: extension, ios, letter-spacing, line-height, nsattributedstring, nskeyvalueobservation, strikethrough, swift, typography, uikit, uilabel, underline
- Language: Swift
- Homepage: http://blog.eppz.eu/uilabel-line-height-letter-spacing-and-more-uilabel-typography-extensions/
- Size: 6.7 MB
- Stars: 56
- Watchers: 3
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# UILabel Typography Extensions 📐
Set `UILabel` line height, letter spacing (and more).```Swift
let headerLabel = UILabel()
headerLabel.textColor = UIColor(named: "Mars")
headerLabel.font = UIFont(name: "HelveticaNeue-CondensedBlack", size: 100)
headerLabel.lineHeight = 80
headerLabel.letterSpacing = 100 * -0.02
headerLabel.text = "Mars"
```See the complementary article at [**UILabel line height, letter spacing and more** UILabel typography extensions].
## How it works
It is an extension on `UILabel` that adds some typographic properties using [**Objective-C Runtime**] (for stored properties on a Swift extension), [`NSAttributedString`] (for manage typographic properties), and [`NSKeyValueObservation`] (to be able to use the regular `text` property to manage text content).
It also takes care of `baselineOffset` values to keep the text content in the vertical center (right). By default, `NSAttributedString` sticks multiline label content to the top of the container view (left), which makes it hard to
match the UI with the design specifications.Using this extension you can build screens that 100% match design specifications. More on that in the article at [**UILabel line height, letter spacing and more** UILabel typography extensions].
## License
> Licensed under the [**MIT License**](https://en.wikipedia.org/wiki/MIT_License).
[**Objective-C Runtime**]: https://developer.apple.com/documentation/objectivec/objective-c_runtime
[`NSAttributedString`]: https://developer.apple.com/documentation/foundation/nsattributedstring
[`NSKeyValueObservation`]: https://developer.apple.com/documentation/foundation/nskeyvalueobservation
[**UILabel line height, letter spacing and more** UILabel typography extensions]: http://blog.eppz.eu/uilabel-line-height-letter-spacing-and-more-uilabel-typography-extensions/