Modify UISearchBar width in a UITableView header
I'm running the following snippet of code (in ViewDidLoad method of a UITableViewController) to create a UISearchBar and add it to a UITableView header.
UISearchBar search = new UISearchBar();
search.SizeToFit (); // How to modify width?
TableView开发者_开发技巧.TableHeaderView = searchBar;
Do you if there is a workaround to modify the width of the UISearchBar. The previous snippet of code allows the bar to have a width as the screen one. Giving a frame to the bar seems not working.
Thank you in advance.
EDIT: The sample has been created for MonoTouch, but it can apply for iOS in general.
This is the solution that I found:
- create a UIToolbar
- add the UISearchBar to that toolbar
- add the toolbar to the header of a UITableView
Since in a UIToolbar it is possible to insert space elements (i.e. UIBarButtonItemFlexibleSpace), the width of a search bar can be modified easily.
精彩评论