如何更改UITextField中的清除按钮颜色或背景颜色。我尝试获取textField的子视图,但是在子视图中没有清除按钮。
答案 0 :(得分:1)
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
}
}
}
}