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
}
}
After the textColor is set, the value needs to be reassigned to the textField.
textField.color = newColor
textField.text = text
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With