Member-only story
How to Change the Search Icon in a UISearchBar
Customize the left and right icons of a UISearchBar — compatible with all iOS versions
Published in
2 min readMay 25, 2020

Let’s start with UITextField
As you probably know, Apple has made not easy for us to access the UITextField
reference on other OS versions. So here’s the code to help you guys gain safe access to UITextField
across all iOS versions:

Change UISearchBar Left Icon

Now, with just a single line of code, you can change the left search icon in your UISearchBar
:
searchBar.setLeftImage(UIImage(named: "dark mode")!)
Change UISearchBar Right Icon

Now, with just single line of code, you can change UISearchBar
right view icon.