我目前正在使用searchBar
我将左侧图标更改为自定义UIImageView。当按下按钮时,我想将其更改回原始搜索图标。
//my custom search iconBar
searchBar.setImage(UIImage(named:"img1"), for: .search, state: .normal)
func changeSearchBarIconBackToOriginal {
//searchbar icon should be back to original image here
}
答案 0 :(得分:0)
您可以将最后一张图像存储在变量中,并将搜索栏的图标设置为按下该按钮时的图标。
示例:
var lastIcon: UIImage?
...
lastIcon = searchBar.image(for: .search, state: .normal)
searchBar.setImage(UIImage("img"), for: .search, state: .normal)
然后,在按下的功能中: func changeSearchBarIconBackToOriginal(){ searchBar.setImage(lastIcon,for:。search,state:.normal) }