Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/joncardasis/fontfit
- Owner: joncardasis
- License: mit
- Created: 2019-10-02T14:26:48.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-04T15:37:48.000Z (over 5 years ago)
- Last Synced: 2023-08-03T17:02:19.081Z (over 1 year ago)
- Topics: aspect-fit, font, size, swift
- Language: Swift
- Homepage: https://medium.com/@joncardasis/dynamic-text-resizing-in-swift-3da55887beb3
- Size: 5.18 MB
- Stars: 37
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![]()
![]()
![]()
![]()
![]()
![]()
![]()
## 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.