Swift テキストカラーを変えるサンプル

環境
Swift version 5.2.3 (swift-5.2.3-RELEASE)
Ubuntu 20.04.2 LTS

構文

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Button(xxx)
.foregroundColor(color) //引数に文字色を指定する
Button(xxx) .foregroundColor(color) //引数に文字色を指定する
Button(xxx)
   .foregroundColor(color) //引数に文字色を指定する

ButtonにforegroundColor修飾子を付与します。
foregroundColor修飾子の引数にテキストカラーを指定します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
struct ContentView: View {
var body: some View {
VStack {
Button("Button") {
print("test")
}
.padding(18)
.foregroundColor(.white)
.background(.green)
}
}
}
struct ContentView: View { var body: some View { VStack { Button("Button") { print("test") } .padding(18) .foregroundColor(.white) .background(.green) } } }
struct ContentView: View {
    var body: some View {
        VStack {
            Button("Button") {
                print("test")
            }
            .padding(18)
            .foregroundColor(.white)
            .background(.green)
        }
    }
}

 

Swift

Posted by arkgame