どうも、ちょげ(@chogetarou)です。
TextEditorの入力文字の色を変更する方法を紹介します。
方法
TextEditorの入力文字の色を変更するには、foreground修飾子を使います。
まず、TextEditorにforegroundColor修飾子を付与します。
そして、foregroundColor修飾子の引数に文字色を指定します。
TextEditor(text: $editText)
.foregroundColor(色)
foregroundColor修飾子の引数に指定した色が入力した文字の色になります。
使用例
struct ContentView: View {
@State var editText = ""
var body: some View {
VStack {
TextEditor(text: $editText)
.foregroundColor(.red)
.frame(width: 200, height: 100)
.border(Color.black, width: 2)
}
}
}
コメント