SwiftUIでText中の文字の太さや色を変える


SwiftUIでText中の文字の太さや色を変える方法です。 SwiftUI で Text を結合できるのが面白いです。

Text Color and Change Font

ContentView.swift

import SwiftUI

struct ContentView: View {
    var body: some View {
        (Text("I ")
            + Text("love ")
                .foregroundColor(Color.red)
            + Text("Snorlax")
                .foregroundColor(Color.black)
                .font(Font.system(size: 20).bold())
            
            + Text("!\n")
            + Text("Snorlax is most cute & cool& powerful Pokemon.")
            ).lineSpacing(4)
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
            .previewLayout(.sizeThatFits)
    }
}