INSSearchBar is a 3rd-party search bar with beautiful animation. Unfortunately, it seems like INSSearchBar is no longer update anymore.
So, heres the DAOSearchBar.
-
iOS 12.0 up
-
Swift 3.0 up (Support Swift 5.0)
pod 'DAOSearchBar', '~> 1.3'
self.searchBarWithoutDelegate.frame = CGRect(x: 20.0, y: 64.0, width: self.view.bounds.width - 40.0, height: 34.0)
self.view.addSubview(self.searchBarWithoutDelegate)
class ViewController: UIViewController, DAOSearchBarDelegate {}
self.searchBarWithDelegate.frame = CGRect(x: 20.0, y: 184.0, width: 44.0, height: 34.0)
self.searchBarWithDelegate.delegate = self;
self.view.addSubview(self.searchBarWithDelegate)
self.searchBarWithCustomColor.searchOffColor = UIColor.darkGray
self.searchBarWithCustomColor.searchOnColor = UIColor.white
self.searchBarWithCustomColor.searchBarOffColor = UIColor.white
self.searchBarWithCustomColor.searchBarOnColor = UIColor.darkGray
func destinationFrameForSearchBar(_ searchBar: DAOSearchBar) -> CGRect
{
return CGRect(x: 20.0, y: 184.0, width: self.view.bounds.size.width - 40.0, height: 34.0)
}
func searchBar(_ searchBar: DAOSearchBar, willStartTransitioningToState destinationState: DAOSearchBarState)
{
// Do whatever you deem necessary.
}
func searchBar(_ searchBar: DAOSearchBar, didEndTransitioningFromState previousState: DAOSearchBarState)
{
// Do whatever you deem necessary.
}
func searchBarDidTapReturn(_ searchBar: DAOSearchBar)
{
// Do whatever you deem necessary.
// Access the text from the search bar like searchBar.searchField.text
}
func searchBarTextDidChange(_ searchBar: DAOSearchBar)
{
// Do whatever you deem necessary.
// Access the text from the search bar like searchBar.searchField.text
}