Search code examples
iosswifticonscustomizationuisearchbar

How to change UISearchBar Icon to custom image?


Currently, I have the default magnifying glass as my search bar icon. However, I want to put a custom image in its place, particularly this image:

Custom Arrow Icon

Screen Shot

How would I go about changing the search bar default icon to the custom image?


Solution

  • you can use setImage function

     searchBar.setImage(UIImage(named: "your image"), forSearchBarIcon: .Search, state: .Normal)
    

    Swift3

    searchBar.setImage(UIImage(named: "Image Name"), for: .search, state: .normal)