「Swift」TextビューにforegroundColor()で文字の色を指定する
書式
.foregroundColor(Color.カラー名)
foregroundColor()で表示する文字の色を指定します。
使用例
struct ContentView: View {
var body: some View {
VStack {
Text("赤色").foregroundColor(Color.red)
Text("青色").foregroundColor(Color.blue)
Text("黄色").foregroundColor(Color.yellow)
Text("緑色").foregroundColor(Color.green)
Text("オレンジ色").foregroundColor(Color.orange)
Text("ピンク色").foregroundColor(Color.pink)
Text("紫色").foregroundColor(Color.purple)
Text("黒色").foregroundColor(Color.black)
Text("グレー色").foregroundColor(Color.gray)
}
}
}
struct ContentView: View {
var body: some View {
VStack {
Text("赤色").foregroundColor(Color.red)
Text("青色").foregroundColor(Color.blue)
Text("黄色").foregroundColor(Color.yellow)
Text("緑色").foregroundColor(Color.green)
Text("オレンジ色").foregroundColor(Color.orange)
Text("ピンク色").foregroundColor(Color.pink)
Text("紫色").foregroundColor(Color.purple)
Text("黒色").foregroundColor(Color.black)
Text("グレー色").foregroundColor(Color.gray)
}
}
}
struct ContentView: View { var body: some View { VStack { Text("赤色").foregroundColor(Color.red) Text("青色").foregroundColor(Color.blue) Text("黄色").foregroundColor(Color.yellow) Text("緑色").foregroundColor(Color.green) Text("オレンジ色").foregroundColor(Color.orange) Text("ピンク色").foregroundColor(Color.pink) Text("紫色").foregroundColor(Color.purple) Text("黒色").foregroundColor(Color.black) Text("グレー色").foregroundColor(Color.gray) } } }