.fixedSize(horizontal: false, vertical: true) to the Text view to allow vertical expansion and enable multi-line wrapping.Why this happens
SwiftUI’s semantic fonts—.title, .headline, .subheadline, and similar—carry an implicit layout preference: they would rather truncate with an ellipsis than grow vertically. When you apply one of these fonts to a Text view, the view’s internal sizing logic treats the ideal height as a single line, so .lineLimit(nil) (or any large number) is effectively ignored. The text measures itself at one line, the parent layout allocates that height, and the remaining content is clipped or ellipsized.
This behavior is intentional for headlines in tight spaces, but it surprises developers who expect lineLimit(nil) to mean “unlimited lines.” The modifier only sets the maximum number of lines; it does not force the view to request more height. Because the semantic font’s ideal size stays at one line, the layout system never sees a reason to expand.
How to fix it
1. Apply fixedSize(horizontal: false, vertical: true) (recommended)
The most direct fix tells SwiftUI to ignore the view’s ideal width constraint while respecting its ideal height. This lets the text wrap to as many lines as needed without expanding horizontally beyond its proposed width.
VStack(alignment: .center) {
Text("SwiftUI is a modern way to declare user interfaces for any Apple platform. ")
.font(.title)
.foregroundStyle(.red) // .color is deprecated
.fixedSize(horizontal: false, vertical: true)
Text("Create beautiful, dynamic apps faster than ever before.")
.font(.system(size: 20))
.fixedSize(horizontal: false, vertical: true)
}
.padding(.horizontal, 10)
Why it works: fixedSize with horizontal: false keeps the text within the offered width (so it still wraps at the container edge), while vertical: true allows the height to grow to fit all lines. The text now follows standard wrapping rules instead of the headline truncation heuristic.
2. Use a non-semantic font or explicit Font initializer
If you don’t need the dynamic-type scaling behavior of semantic fonts, switch to a fixed-size or custom font. A plain .system(size:weight:design:) or .custom(...) does not carry the same truncation bias.
Text("Long headline that should wrap across multiple lines.")
.font(.system(size: 28, weight: .bold, design: .default))
.lineLimit(nil) // now works as expected
This avoids the special sizing logic entirely, but you lose automatic Dynamic Type scaling. Prefer the fixedSize approach when accessibility scaling matters.
3. Wrap in a ScrollView for very long content
When the text might exceed the available screen height, combine fixedSize with a scroll view so the view can grow vertically and then scroll.
ScrollView {
VStack(alignment: .leading, spacing: 12) {
Text(longHeadline)
.font(.title)
.fixedSize(horizontal: false, vertical: true)
Text(longBody)
.font(.body)
.fixedSize(horizontal: false, vertical: true)
}
.padding()
}
How to prevent it
- Default to
.fixedSize(horizontal: false, vertical: true)on anyTextthat uses.title,.headline,.subheadline, or other semantic styles and might wrap. - Avoid
.lineLimit(nil)alone as a wrapping guarantee; it only sets a ceiling, not a floor. - Test with Dynamic Type sizes (Settings → Accessibility → Display & Text Size → Larger Text) to catch truncation early.
- Use Xcode’s Debug → View Debugging → Show Layout Bounds to see when a text view’s frame is shorter than its content.
FAQ
Does lineLimit(nil) ever work with semantic fonts?
Only when the parent view forces extra height (for example, inside a VStack that has spare space and no other constraints). In most real layouts the parent sizes to the child’s ideal height, which stays at one line for semantic fonts.
Is fixedSize(horizontal: false, vertical: true) a performance concern?
No. It merely relaxes the vertical compression resistance. The text still measures once per layout pass; there is no extra layout pass or off-screen rendering.
What about multilineTextAlignment?
multilineTextAlignment(.leading/.center/.trailing) controls alignment of wrapped lines, not whether wrapping occurs. You still need fixedSize (or a non-semantic font) to allow the lines to exist in the first place.
Can I create a reusable modifier for this?
Yes. A small view modifier keeps call sites clean:
extension View {
func allowsWrapping() -> some View {
fixedSize(horizontal: false, vertical: true)
}
}
// Usage
Text("…").font(.title).allowsWrapping()
Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.