//MARK: SEARCH BAR DELEGATE
extension HomeViewController: UISearchBarDelegate
{
func searchBarTextDidBeginEditing(_ searchBar: UISearchBar)
{
//Show Cancel
searchBar.setShowsCancelButton(true, animated: true)
searchBar.tintColor = UIColor.black
}
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String)
{
guard let term = searchBar.text , term.trim().isEmpty == false else {
return
}
}
func searchBarSearchButtonClicked(_ searchBar: UISearchBar)
{
//Hide Cancel
searchBar.setShowsCancelButton(false, animated: true)
guard let term = searchBar.text , term.trim().isEmpty == false else {
return
}
}
func searchBarCancelButtonClicked(_ searchBar: UISearchBar)
{
//Hide Cancel
searchBar.setShowsCancelButton(false, animated: true)
searchBar.text = String()
searchBar.resignFirstResponder()
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.