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

3 views0 comments
bottom of page