项目有皮肤切换,UITextField的清除按钮在暗环境下几乎看不到,所以要更改样式,更换图片
class EXAssetTextField: UITextField {
// CYC666
override func layoutSubviews() {
super.layoutSubviews()
self.changeClearButtonImage()
}
// MARK: 修改清除按钮图片
@objc func changeClearButtonImage() {
if let temp = self.value(forKey: "_clearButton") {
let btn = temp as! UIButton
btn.setImage(CTools.getImage("EXAssets49"), for: .normal) // 此处自行修改图片
} else {
var btn: UIButton?
for item in self.subviews {
if item is UIButton {
btn = item as! UIButton
break
}
}
if btn != nil {
btn?.setImage(CTools.getImage("EXAssets49"), for: .normal) // 此处自行修改图片
}
}
}
}