Nostradamus
Nostradamus

Reputation: 1557

Is it possible to add images to scope filter buttons in a UISearchController?

I'm trying to jazz up an interface with a UISearchController. I'd like to include scope filtering, but would like to have graphics in place of the text in the scope buttons. How can I do that?

Upvotes: 0

Views: 166

Answers (1)

rmaddy
rmaddy

Reputation: 318824

UISearchBar provides the API for setting up scope bar buttons. Unfortunately the public API only supports string titles for the scope buttons. There is an API to set a background image for the scope bar itself and there is an API to set a background image for all of the buttons for a given state, but you can't set individual images for each button that could replace the string titles.

You might be able to dig into the private subview structure of the scope bar portion of the search bar. This may give you access to some sort of UIButton class. You could then set an image for each of those buttons using the standard public UIButton API. But such a solution is never wise since it digs into the private, undocumented, view hierarchy that is likely to change in some future iOS update. And it could possibly cause your app to be rejected.

Upvotes: 2

Related Questions