Multiline Text & Alignment
Control line limits, wrapping, and text alignment.
Multiline Text & Alignment is a free SwiftUI Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the SwiftUI Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
When Text Gets Long
Short labels fit on one line, but paragraphs wrap. This lesson shows how to control wrapping, line limits, and alignment for longer text. 📝
Text Wraps by Default
SwiftUI wraps long text onto multiple lines automatically when there is room. You usually do not need to do anything for basic wrapping.
Text("A fairly long sentence that will wrap onto more than one line.")Limiting Lines
The lineLimit modifier caps how many lines show. Extra text is truncated with an ellipsis, which is great for previews and cards.
Text(longBio)
.lineLimit(2)Truncation Mode
Control where the cut happens with truncationMode. Choose .tail, .head, or .middle depending on which part matters most.
Text(path)
.lineLimit(1)
.truncationMode(.middle)Aligning Multiline Text
Use multilineTextAlignment to align wrapped lines left, center, or trailing. It only affects text that spans more than one line.
Text(quote)
.multilineTextAlignment(.center)Frame Versus Text Alignment
Remember the difference: frame alignment positions the whole block, while multilineTextAlignment arranges lines inside that block.
Centering a Block
To center a block and its lines, give it a wide frame and a center text alignment together. Both work as a pair.
Text(notice)
.multilineTextAlignment(.center)
.frame(maxWidth: .infinity)Line Spacing
Add breathing room between lines with lineSpacing. A few extra points often makes dense paragraphs much easier to read.
Text(article)
.lineSpacing(6)Allowing Tight Layout
When space is tight, minimumScaleFactor lets text shrink instead of truncating, keeping the whole message visible.
Text(headline)
.lineLimit(1)
.minimumScaleFactor(0.7)Fixed Size to Avoid Clipping
If wrapping text gets squeezed, fixedSize tells it to keep its ideal height so nothing gets unexpectedly clipped.
Text(message)
.fixedSize(horizontal: false, vertical: true)Putting It Together
Combine lineLimit, alignment, and spacing to craft readable cards. Small tweaks add up to a polished reading experience.
Quick Check
Which modifier aligns wrapped lines of text?
Lesson Recap
You shaped long text with lineLimit, truncation, alignment, and spacing. These tools keep paragraphs tidy and easy to read. 👍
Frequently asked questions
Is the “Multiline Text & Alignment” lesson free?
Yes — the full text of “Multiline Text & Alignment” is free to read here on the web, and the SwiftUI Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the SwiftUI Academy course, upgrade to CoddyKit PRO.
What will I learn in “Multiline Text & Alignment”?
Control line limits, wrapping, and text alignment. You practise SwiftUI Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start SwiftUI Academy?
No prior experience is required. SwiftUI Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Multiline Text & Alignment” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this SwiftUI Academy lesson?
Yes. Every SwiftUI Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Fonts, Weight & Color
- Multiline Text & Alignment
- Loading Images from Assets
- Using SF Symbols