Multiline text in SwiftUI
02 Jul 2020
I keep running into an issue in SwiftUI where some text truncates where I don’t expect it to. Here’s an example from Personal Best’s onboarding screen:
I’m sure that I’m doing something wrong here, or perhaps misunderstanding how SwiftUI’s layout system works. But for now, I made a modifier that I can apply to stop this from happening:
// View modifier
struct Multiline: ViewModifier {
func body(content: Content) -> some View {
content.fixedSize(horizontal: false, vertical: true)
}
}
// Using it
Text("Hello world").modifier(Multiline())
One day I’ll figure out the layout system a bit more so I won’t need to do this, but for now it’s doing the trick for me.
Thanks for reading.
To get in touch, email me or find me on Mastodon.
If you liked this post, you'll love my iOS apps. Check them out below.

Personal Best
Level up your workouts
Taylor's Version
Upgrade Taylor Swift songs in your playlists
SalaryPig
Meet Trevor, the salary-tracking pig
Taylor Swift Quiz
How well do you know Taylor Swift?