top of page

Text in SwiftUI: It’s as Easy as ABC! 🎉🔡🕵🏿

Updated: Mar 20, 2023

Greetings, iOS developers! Are you ready to master the art of displaying text in SwiftUI? In this short and fun article, we’ll show you how to make your text shine using SwiftUI’s Text view. No more plain, boring text – let's get the party started! 🥳🌈



The Basics: Hello, Text! 🖐🏿

Displaying text in SwiftUI is a walk in the park! 🌳🚶🏿‍♂️ Just use the Text view and pass in your string:

Text("Hello, SwiftUI!")

Congratulations! You’ve just created your first Text view! 🎊

Customizing Text: Dress to Impress 👗🎩

Time to make your text stand out with some styling! Think of it as dressing up your text for a fancy night out. 💃🏿

Fonts and Sizes 📏

To change the font and size, use the font() modifier:

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

Now your text is bold and beautiful! 😍

Colors 🌈

Add a splash of color with the foregroundColor() modifier:

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

Your text is red hot! 🔥

Line Limit and Truncation 📜

Control the number of lines and truncation mode with the lineLimit() and truncationMode() modifiers:

Text("A very long text that we want to limit to two lines...")
    .lineLimit(2)
    .truncationMode(.tail)

Short and sweet, just like this article! 😜

Combining Text: It’s Like a Text Sandwich 🥪

Need to mix and match styles? Combine multiple Text views using the +operator:

Text("Hello, ").foregroundColor(.red) +
Text("SwiftUI!").foregroundColor(.blue)

Now you’ve got red and blue text side by side! 🚨

Wrapping Up: Text-ceptional! 🌟

And that’s a wrap! With your newfound text prowess, your SwiftUI apps will be the talk of the town! Remember, when it comes to text in SwiftUI, the sky’s the limit. So go ahead and explore, experiment, and have a blast! 🚀

Give Support or Tip👋🏿

Give a Tip with CashApp: https://cash.app/$DiAlcatic

6 views0 comments
bottom of page