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

Mukesh Mandora
Better Programming
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:

Code snippet for accessing textfield and changing it’s properties

Change UISearchBar Left Icon

Code snippet for adding left icon in UISearchBar

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

Code snippet for adding right icon in UISearchBar

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

--

--

No responses yet

Write a response