The clean and shiny search bar that does what UISearchBar does only with dirty hacks. This view is designed to tackle the customization limits of UISearchBar. The difference here is that this class does not inherit UISearchBar but composes a new UIView object by using a UITextField that is much easier to use. These are the limits of the UISearchBar:
- no clean way to left align the placeholder
- the cancel button is hard to taylor to your needs
- generally the appearance is not customizable (e.g. the font of the text)
- there are some strange behaviours when you set a custom background image
Since I use a UITextField these restrictions do not apply.
SHSearchBar is compatible with iOS 8
or higher and builds with Xcode 9
and Swift 4
syntax. It is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "SHSearchBar"
The repo includes an example project. It shows shows different use cases of the searchbar. To run it, clone the repo and run pod install
from the Example directory first. The following images show some of these use cases:
You can show a custom placeholder like for normal text fields:
And you can even type text into that searchbar:
Wow there are customizable accessory views too:
Easily customize text and cancel button as you want:
You can customize each corner radius of the text field so that layouts like this become an ease:
The inner text field supports the new iOS 10 'textContentMode':
(Re-uses the address searched in Apple Maps before)
You can use the search bar inside a UINavigationBar:
Stefan Herold, [email protected]
SHSearchBar is available under the MIT license. See the LICENSE file for more info.