Reputation: 33428
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.
Upvotes: 0
Views: 1094
Reputation: 33428
This is the solution that I found:
Since in a UIToolbar it is possible to insert space elements (i.e. UIBarButtonItemFlexibleSpace), the width of a search bar can be modified easily.
Upvotes: 1