I want to change myTextField background color to the color I type into the same myTextField. Here is my method: and I also called this method in the viewDidLoad section: changeColor() but it doesn't work :(
func changeColor() {
if myTextField.text == "blue" {
myTextField.backgroundColor = .blue
} else if myTextField.text == "red" {
myTextfield.backgroundColor = .red
} else {
myTextField.backgroundColor = .black
}
}
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if textField == myTextField {
if range.location > 3 {
return false
}
}
return true
}