I need the search bar under the navigation title how to do that programmatically or via story board.
UISearchBar *searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0,30, 250,44)];
searchBar.placeholder = @"Search";
UIBarButtonItem *searchBarItem = [[UIBarButtonItem alloc]initWithCustomView:searchBar];
searchBarItem.tag = 123;
searchBarItem.customView.hidden = YES;
searchBarItem.customView.alpha = 0.0f;
self.navigationItem.leftBarButtonItem = searchBarItem;
self.navigationItem.title = @"locations";
You have added the search bar as
UIBarButtonItem
, thats why it is not visible.If you want to display the search bar in place of the title view of navigation bar the use this code
Code to show navigation bar in place of Title of Navigation :
Output :
Code to show navigation bar below the Navigation bar:
UPDATE :
Output :
Updated output
To customize the textField :
The image I have used is of height 30 pixel like the search bar's text field.
here is the image :
And output :
Hope it helps ...
Happy coding ...
We can also use textbox as search bar, it is working fine in my app,
Go to
StoryBoard
and do the following changesFrom Object
Library--> type view
and drag tostoryboard
and paste below the Navigation bar.Add the textbox to the view and assign the outlets and delegates.
now go to
viewcontroller.m
and paste the following codeNow it will work fine..