UITextField 清除按钮颜色 Swift
UITextField clear button color Swift
如何更改 UITextField 中的清除按钮颜色或背景颜色。我尝试获取 textField 的子视图,但在子视图中没有清除按钮。
import UIKit
class CustomTextField: UITextField {
override func layoutSubviews() {
super.layoutSubviews()
for view in subviews {
if let button = view as? UIButton {
button.setImage(button.image(for: .normal)?.withRenderingMode(.alwaysTemplate), for: .normal)
button.tintColor = .white
}
}
}
}
如何更改 UITextField 中的清除按钮颜色或背景颜色。我尝试获取 textField 的子视图,但在子视图中没有清除按钮。
import UIKit
class CustomTextField: UITextField {
override func layoutSubviews() {
super.layoutSubviews()
for view in subviews {
if let button = view as? UIButton {
button.setImage(button.image(for: .normal)?.withRenderingMode(.alwaysTemplate), for: .normal)
button.tintColor = .white
}
}
}
}