gpt4 book ai didi

ios - 如何在 UITextField 的 shouldChangeCharactersIn 中有效地处理多个文本字段

转载 作者:行者123 更新时间:2023-11-28 05:48:48 24 4
gpt4 key购买 nike

我有许多文本字段,我想在用户在文本字段中输入时将文本颜色更改为白色。以下是我的代码,其中包含很多似乎效率不高的 if 条件。有什么办法可以不用写很多 if 条件吗?

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {

if textField == emailTextField {
emailTextField.textColor = .white
} else if textField == nameTextField {
nameTextField.textColor = .white
} else if textField == addressTextField {
addressTextField.textColor = .white
}

return true
}

最佳答案

就这样

textField.textColor = .white

无论 textfield 是什么,它的 textColor 都会被改变

关于ios - 如何在 UITextField 的 shouldChangeCharactersIn 中有效地处理多个文本字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53712543/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com