How to style Text in SwiftUI?

Uplift iOS Interview

"Uplift iOS Interview" is a comprehensive guide to help aspiring iOS developers soar to new heights in their careers. This book is an indispensable tool for anyone looking to crack the iOS interview and impress their future employers with their technical prowess. With in-depth coverage of Swift, AutoLayout, SwiftUI, Multithreading, Memory management so on and so forth, this book is a treasure trove of knowledge for anyone looking to uplift their iOS development career.

In this blog post, we’re going to explore how to style text in SwiftUI. Text is a fundamental element in any app and being able to control its appearance is crucial for creating a polished, professional-looking user interface. In this post, we’ll cover some of the ways you can adjust the font, color, and other attributes of text in SwiftUI.

One of the most basic ways to style text in SwiftUI is by adjusting the font. The font() modifier can be used to set the font of a text view. You can specify the font to be the system font at a certain size, for example:

Text("Hello, World!")
    .font(.system(size: 24))

You can also use custom fonts by providing the font’s name. For example, the following code sets the text’s font to “Avenir Next” with a size of 24 points:

Text("Hello, World!")
    .font(.custom("Avenir Next", size: 24))

In addition to adjusting the font, you can also make text bold or italic, or adjust the font weight or design using the .bold(),.italic() etc.

Text("Hello, World!")
    .font(.system(size: 24, weight: .bold, design: .rounded))

The foregroundColor() modifier can be used to change the text’s color. For example, the following code sets the text’s color to red:

Text("Hello, World!")
    .foregroundColor(.red)

You can also use the background() modifier to change the background color of the text view. For example, the following code sets the text’s background color to green:

Text("Hello, World!")
    .background(.green)

Another interesting feature is the ability to adjust the spacing between characters, lines and paragraphs tracking() adjust character spacing, lineSpacing() adjust line spacing.

Text("Hello, World!")
    .lineSpacing(20)

Finally, SwiftUI also provides a variety of other text-related modifiers, such as lineLimit(), multilineTextAlignment(), and truncationMode(), that can be used to control the appearance of text in various ways.

In conclusion, SwiftUI provides a powerful set of tools for styling text. By using the various font, color, spacing and other modifiers, you can create text that looks exactly the way you want it to, and that fits perfectly into your app’s design.


Rev Up Your iOS Skills: Take a Dynamic Learning Journey
iOS Career Boost

iOS Career Boost is the ultimate learning journey to elevate your iOS development career through a dynamic blend of visual learning, handy cheat sheets, coding practice materials, and expertly curated tips and tricks


Get Ready to Shine: Mastering the iOS Interview


Enjoying the articles? Get the inside scoop by subscribing to my newsletter.

Get access to exclusive iOS development tips, tricks, and insights when you subscribe to my newsletter. You'll also receive links to new articles, app development ideas, and an interview preparation mini book. Your email address will only be used for the purpose of sending the newsletter and will not be shared with third parties or advertisers. Rest assured that we value your privacy and will not spam your inbox.


Connect with me on

Twitter and LinkedIn and don't hesitate to reach out with any questions about this post. Thank you for reading.

If you know someone who would benefit from reading this article, please share it with them.