UISearchBar: Changing the appearance - Shape, Back

2019-02-20 21:39发布

问题:

I'd like to change the appearance of the default UISearchBar. As an example, how would you recreate the search box in the Google iPhone app as seen below? How would you overlay an image to produce this effect?

回答1:

Upon some investigating of possibilites to customize the search bar, I'm inclined to say this is a custom component that has nothing to do with UISearchBar, but instead recreates its functionality.



回答2:

You don't need to subclass anything. Create a new UIView that has the buttons and text field and then when then entire view is going to load do this:

[self.searchDisplayController.searchBar addSubview:customSearchBarView];

Make sure to set the new text field as the first responder so it has access to the keyboard.