Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

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). 📐

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/