Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/joncardasis/fontfit

↔ Aspect-fit a font inside a view container.
https://github.com/joncardasis/fontfit

aspect-fit font size swift

Last synced: about 1 month ago
JSON representation

↔ Aspect-fit a font inside a view container.

Awesome Lists containing this project

README

        


ChromaColorPicker 2.0









## Abstract
FontFit scales the `font` size of a text element (i.e. `UILabel` or `UITextView`) to fill it's container.

FontFit is the missing inverse of `sizeToFit()`. The `FontFit` extensions are a more detailed implementation of UILabel's [adjustsFontSizeToFitWidth](https://developer.apple.com/documentation/uikit/uilabel/1620546-adjustsfontsizetofitwidth) which only _reduces_ font size.

## Examples
**Note**: A full example use case can be found in the _Example_ project.

```Swift
let label = UILabel(frame: ...)

// Increase font to fill the label's frame.
label.fitTextToBounds()
```

```Swift
let label = UILabel(frame: ...)

// Increase font to fill the label's frame, attempting to distribute onto, at most, 2 lines.
label.fitText(maxLines: 2)
```
## License
FontFit is available under the MIT license. See the LICENSE file for more info.