How to set Color for Text view in SwiftUI?

SwiftUI – Text Font Color / Foreground Color

To set font color for text in Text view, call foregroundColor() method on this Text view. foregroundColor() sets the color of the text in Text view.

Example

In the following example, we created a Text view, and called foregroundColor() method on the Text view to change the text color to blue.

ContentView.swift

import SwiftUI

struct ContentView: View {
    var body: some View {
        Text("Hello, world!")
            .foregroundColor(.blue)
    }
}

Screenshot

SwiftUI - Text Font Color / Foreground Color
Text view – Color

Now, let us choose a color with specific values for Red, Green, Blue and Opacity channels.

ContentView.swift

import SwiftUI

struct ContentView: View {
    var body: some View {
        Text("Hello, world!")
            .foregroundColor(Color.init(Color.RGBColorSpace.sRGB,
                                        red: 1.0,
                                        green: 0.2,
                                        blue: 0.4,
                                        opacity: 1.0))
    }
}

Screenshot

Text view – RGB color

Summary

Summarising this SwiftUI Tutorial, we learned how to set color to the text in Text view.