I'm building an app in SwiftUI which contains a lot of components, including a Text view which contains a long string.
When I launch the app on iPhone 11 everything works perfectly, but when I launch it on a smaller device (iPhone SE for example), the Text view cuts the text in the middle, and shows three dots (...) instead of the rest of the text.
What would be the best solution for this? Is there an equivalent for UILabel's adjustsFontSizeToFitWidth in SwiftUI?
Thank you!
Not exactly, but kind of...
Text("Your long next here")
.minimumScaleFactor(0.2) // value is up to you
You can use a really large font size and use func minimumScaleFactor(_ factor: CGFloat) to let the text shrink. You can also add lineLimit(1) to force the text to be on one line.
Text("My long text adjusted to fit width")
.font(.system(size: 200))
.minimumScaleFactor(0.0001)
.lineLimit(1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With