Skip to content

πŸ‘©πŸ»β€πŸ’» πŸ§‘πŸ½β€πŸ’» Subscribe and Read us on Substack to Get Full Access to Our Posts


SwiftUI Text

The Text view in SwiftUI is incredibly versatile, allowing for the display of static text or dynamic content passed through variables. It supports styling, formatting, and localization, making it a powerful tool for developers to present information in their apps. This guide will walk you through the basics to more advanced uses of Text, making your apps more interactive and engaging.

import SwiftUI

struct SwiftUI_Text: View {
    var body: some View {
        
           Text("Hello, UIExamples.com readers!")
               .font(.title) // Sets the font to a title size.
               .fontWeight(.bold) // Makes the text bold.
               .foregroundColor(.blue) // Sets the text color to blue.
               .multilineTextAlignment(.center) // Centers the text.
               .padding() // Adds padding around the text.
       }
    
}

#Preview {
    SwiftUI_Text()
}

This code snippet showcases a basic Text view with various modifiers applied to customize its appearance. It’s a simple yet effective way to understand how text can be manipulated in SwiftUI to fit the design needs of your application.

Basic Text Display

Text("Hello, UIExamples.com!")

This simple line of code displays a basic string. However, SwiftUI’s Text goes far beyond displaying static content.

Styling Text

Customize your text’s appearance to fit your app’s design. You can change the font, color, and weight.

...

πŸ”’ The remaining content of this article is only available on our Substack!

Back To Top
Search