Swift テキストカラーを変えるサンプル
環境
Swift version 5.2.3 (swift-5.2.3-RELEASE)
Ubuntu 20.04.2 LTS
構文
Button(xxx)
.foregroundColor(color) //引数に文字色を指定する
Button(xxx)
.foregroundColor(color) //引数に文字色を指定する
Button(xxx) .foregroundColor(color) //引数に文字色を指定する
ButtonにforegroundColor修飾子を付与します。
foregroundColor修飾子の引数にテキストカラーを指定します。
使用例
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) } } }