我创建了一个名为LibrarySearchBar
的自定义搜索栏。当我单击我的搜索栏时,文本字段变得过大。单击“取消”时,文本字段会保持过大。我该如何解决这个问题?
此外,在调试器中,它声明“搜索字段背景图像仅适用于UIControlStateNormal和UIControlStateDisabled.state = 4被解释为UIControlStateDisabled。”
1)点击搜索栏2)点击“取消”
代码:
class LibrarySearchBar: UISearchBar {
init(frame: CGRect, font: UIFont, textColor: UIColor, placeholder: String, placeholderColor: UIColor) {
super.init(frame: frame)
self.frame = frame
self.setSearchFieldBackgroundImage(UIImage(named: "SearchFieldBackground"), for: UIControlState.normal)
self.setSearchFieldBackgroundImage(UIImage(named: "SearchFieldBackgroundSelected"), for: UIControlState.selected)
self.backgroundImage = UIImage(named: "SearchBarBackground")
}
}