The text doesn't get wrapped in swift UI
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
When text does not wrap in SwiftUI, the real problem is usually layout, not the Text view itself. Text can wrap, but only if its parent gives it a finite width and enough priority to use more than one line.
That is why adding random modifiers often does nothing. You have to look at the surrounding stack, frame constraints, and compression behavior to understand why the text stays on one line or gets truncated.
The Most Common Fix
For many cases, especially inside HStack, this combination is enough:
lineLimit(nil) allows multiple lines. fixedSize(horizontal: false, vertical: true) tells SwiftUI not to compress the text vertically into a single-line layout.
If the text still does not wrap, the next thing to inspect is the parent layout.
Why Parent Layout Matters
SwiftUI wrapping depends on available width. If the parent gives the text infinite width or keeps squeezing it horizontally, the text may truncate instead of wrapping.
A classic example is an HStack with an icon and long text:
This often works, but if another sibling view aggressively takes width, the text can still lose the layout negotiation.
Use layoutPriority When Siblings Compete
Inside stacks, SwiftUI decides which views give up space first. If your text is being compressed too aggressively, give it a higher layout priority:
This tells SwiftUI that the text should keep its room before lower-priority sibling views do.
Give the Text a Real Width to Wrap Within
Text cannot wrap meaningfully if there is no effective width constraint. Sometimes the fix is to give the view a frame that expands to the available width:
This is especially useful inside containers where alignment and width are ambiguous.
If you want left-aligned multiline text, pair it with:
That controls line alignment, not wrapping itself, but the two are often confused.
A Full Example
Here is a practical example that wraps reliably in a card-style layout:
This works because the text has multiple lines enabled, enough layout priority, and a parent that gives it meaningful width.
What Usually Does Not Fix It
Some modifiers are often added hopefully but do not address the real issue:
- '
.multilineTextAlignment(.leading)changes alignment, not wrapping' - '
.frame(width:)can help or hurt depending on the chosen width' - '
.lineLimit(nil)alone is often not enough inside constrained stacks'
If the layout still fails, step back and inspect the whole hierarchy rather than stacking more text modifiers blindly.
Common Pitfalls
The biggest pitfall is assuming the problem lives entirely on the Text view. In SwiftUI, parent layout rules decide whether wrapping is even possible.
Another common issue is using HStack with sibling views that take too much width and never giving the text any layout priority.
Developers also confuse truncation and non-wrapping. The text is often allowed to be multiline in theory, but the parent is forcing it into a layout where truncation wins.
Finally, be careful with .fixedSize(). The common fix for wrapping is .fixedSize(horizontal: false, vertical: true), not a version that forces horizontal expansion and breaks the layout in a different way.
Summary
- SwiftUI text wrapping is usually a layout-constraint problem, not a missing text feature.
- Start with
.lineLimit(nil)and.fixedSize(horizontal: false, vertical: true). - If the text is inside a stack, use
layoutPriority(1)when sibling views compete for width. - Give the text a meaningful width with a suitable frame or parent container.
- Inspect the whole layout tree if wrapping still fails, because the parent view is often the real cause.
Related reading
- The use of Swift 3 objc inference in Swift 4 mode is deprecated?
- This Activity already has an action bar supplied by the window decor
- This function declaration is not a prototype warning in Xcode 9
- This Handler class should be static or leaks might occur IncomingHandler
- This version of the application is not configured for billing through Google Play
- Threading Example in Android
- To Do list before publishing Android app to market
- to drawRect or not to drawRect when should one use drawRect/Core Graphics vs subviews/images and why?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.