In my current application, I have created a custom input container for the users to enter comments. Please refer to the picture below.
The textfield is set as the delegate for UITextFieldDelegate, and I would like to work with shouldChangeCharactersInRange such that if the textField is empty, the sendButton is a gray color, and when there is at least 1 character filled in, it changes to blue. However, currently with my code, the sendButton is blue to begin with, turns gray when 1 character is entered, and then back to blue when characters are greater than 1. Kinda weird, trying to figure out why that is. Here is my current relevant code:
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if (textField.text?.characters.count)! > 0 {
sendButton.setTitleColor(ovencloudBlueText, for: .normal)
} else {
sendButton.setTitleColor(newLoginGrayText, for: .normal)
}
return true
}
I know it's probably something simple that I'm missing. If this is a possible repeat, please let me know and I'll delete this post after checking out the reference link. Much thanks for your input.