Skip to content

kylebshr/AestheticText

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AestheticText

A SwiftUI modifier that will compress Text horizontally as much as possible without wrapping to another line - that is, make each line as close in width as possible. For ✨aesthetics✨

Installation and Usage

  • File > Add Package Dependencies...
  • Add https://github.com/kylebshr/AestheticText.git
  • Select “Up to Next Major” with “1.0.0”
import AestheticText

Text(someAwesomeText)
    .aestheticText()

Implementation

This is implemented using a single-view Layout that measures its content using a binary search to find the smallest possible width (with a tuned level of precison) that does not affect the height.

Drawbacks

Since this implementation has no knowledge of the actual content of the Text being rendered, this comes with some drawbacks. For example, it may cause the second line of two lines of text to become longer than the first, since it results in a narrower width, which may actually look worse and be undesirable. For this reason, it works best with centered text, where this behavior doesn’t look off. This screenshot from the demo project illustrates the issue:

Demo app screenshot

About

do it for the ✨aesthetic✨

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages