Dileepa Chandrasekara
Dileepa Chandrasekara

Reputation: 331

How to add a custom button between UISearch Bar and Cancel Button while a search is enabled in Swift?

I'm using iOS 14 SDK for development and I want to add a custom button between UISearchBar and the Cancel button when the search is enabled.

I have checked all attributes in UISearchController and UISearchBar level, but I couldn't find any attribute for doing it. :(

I saw a similar kind of button in the default iOS Files app, I have attached the screenshot and marked it with a red color box. Can someone give a clue for doing that? I really appreciate your help.

enter image description here

Upvotes: 3

Views: 908

Answers (1)

stackich
stackich

Reputation: 5287

You can try this:

if searchController.isActive {
    searchController.searchBar.showsBookmarkButton = true
} else {
    searchController.searchBar.showsBookmarkButton = false
}
searchController.searchBar.setImage(UIImage(named: "imgName"), for: .bookmark, state: .normal)

Upvotes: 1

Related Questions