Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextfield text color is not changing while not in focus

Tags:

ios

So I have two UITextFields: name and amount and two UIButtons: income, expense.
When I press the expense button I want my amount textfield color to change to red or green if income button is pressed.

This only works if amount textfield is in focus, if name textfield is in focus, the color is not changed for amount.

Is there a way to change the color of the textfield if it's not in focus ?

edit:

Here is my code where I change the color:

@IBAction func typeBtnPressed(_ sender: UIButton) {
    if sender.tag == Buttons.expense.rawValue {
        amountTxt.textColor = .red
    } else {
        amountTxt.textColor = .green
    }
}
like image 457
Adrian Avatar asked Dec 13 '22 20:12

Adrian


1 Answers

After the textColor is set, the value needs to be reassigned to the textField.

textField.color = newColor
textField.text = text
like image 58
Swathi Avatar answered Mar 04 '23 11:03

Swathi