STR:
- Enter email into the text field –
test+ap11@gmail.com
- Change the
foregroundColor
of the text field by tapping the "Change color" button
ER: The color of the complete label is changed. The whole label is red.
AR: The label color is changed partly. Some of characters are red, some of them are black.
Environment: Only iOS 16 (iOS 15 is ok)
struct ContentView: View {
@State var text = ""
@State var isRed = false
var body: some View {
VStack {
TextField("enter text here", text: $text)
.foregroundColor(isRed ? .red : .black)
Button {
isRed = !isRed
} label: {
Text("Change color")
}
}
}
}