どうも、ちょげ(@chogetarou)です。
TextFieldのユーザーが入力した文字の色を変える方法を紹介します。
方法

TextFieldの入力文字の色を変えるには、foregroundColorモディファイアを使います。
まず、TextFieldにforegroundColorモディファイアを付与します。
そして、foregroundColorの引数に入力文字の色を指定します。
TextField("Your Text Here", text: $editingText)
.foregroundColor(/*ユーザーが入力した文字の色*/)
foregroundColorモディファイアを使えば、TextFieldの入力したテキストの色を変えることができます。
使用例
以下は、使用例です。

struct ContentView: View {
@State var editingText = ""
var body: some View {
VStack {
TextField("Your Text Here", text: $editingText)
.padding()
.foregroundColor(Color.red)
.textFieldStyle(RoundedBorderTextFieldStyle())
}
}
}
コメント