单击搜索栏会导致文本字段变得过大

时间:2017-07-12 00:46:10

标签: ios swift uisearchbar

我创建了一个名为LibrarySearchBar的自定义搜索栏。当我单击我的搜索栏时,文本字段变得过大。单击“取消”时,文本字段会保持过大。我该如何解决这个问题?

此外,在调试器中,它声明“搜索字段背景图像仅适用于UIControlStateNormal和UIControlStateDisabled.state = 4被解释为UIControlStateDisabled。”

1)点击搜索栏2)点击“取消”

enter image description here enter image description here

代码:

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")
    }
}

0 个答案:

没有答案