Create a search bar like in the iOS 7 Contacts app - ios

I have an application where I have a UITableView with sections which are scrollable on the side through sectionIndexTitlesForTableView:.
In the tableHeaderView of the UITableView I want to add a UISearchBar, which I want to behave like the one Apple is using in their new Contacts app in iOS7. But I can't seem to get it to work.
The search bar is not 100% the width of the screen, but instead has its right side against the section index.
My questions are:
How do I get the search bar's width to 100% when it's the tableHeaderView of a UITableView that has a visible section index?
How can I create a transition like in the Contacts app of iOS 7 where the navigation bar hides and the search bar's grey background extends to the status bar?
I have tried several things already, including adding the search bar in the navigation bar, and using UISearchBarController, but I can't find good documentation on the Apple website on how to create this. Also, the transition guide from iOS6 to iOS7 has been no good help for me.
Here are two pictures that illustrate my problem:

Two main differences to the way Apple do their app, which will solve your problems.
First, their UISearchBar isn't the headerView for the tableView. It's a separate view above the table. You'll need to change your UITableViewController to a UIViewController that has a UITableView positioned just below your UISearchBar.
Second, their UISearchBar has an associated Search Display Controller. Assuming you're using a storyboard file, this comes bundled together for you - just add the UISearchBar with the Search Display Controller. This will handle all of the transitioning to underneath the status bar for you.

Two things:
1) Set tableView's sectionIndexBackgroundColor to [UIColor clearColor].
2) Implement 'viewDidLayoutSubviews' method to fix frame for UISearchBar
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
CGRect barFrame = self.searchBar.frame;
barFrame.size.width = self.view.bounds.size.width;
self.searchBar.frame = barFrame;
}

Related

My UITableView Gets ShiftedDown

I have a UITableView that when first displayed it displays correctly with the first row appearing on top. When I select a cell another UITableView is presented. If I used the back button on the UINavigation Bar the original UITableView is shifted down with a blank space between the UINavigation Bar and the UITableView.
I am not using story boards. I am using XIB files. I am also using a sliding menu that I got the code for from Ray Wenderlich's web site.
When I slide back the main screen over the first UITableView it goes back to its proper position. But then when I select an entry again the issue described above appears.
I found another post that seems to provide an answer to the issue. This post says to make some adjustments like to the translucent settings or the auto-layout settings but doesn't give specifics.
Here is that post: Container View getting pushed down as if it had a UINavigationBar?
Thanks,
Glenn
Add
self.automaticallyAdjustsScrollViewInsets = NO;
in viewDidLoad, of the UIViewController where you have the shifting table view

UISearchBar with solid color in iOS 7+

I've tried to use all the properties UISearchBar has with different combinations, I've searched for the answer for a while but still can't solve the problem.
Problem:
I have a UIViewController with UITableView in it and some other view in storyboard. I've added Search Bar and Screen Display Controller into my project (search bar is added as a subview/header of the UITableView)
I need to make it red color with no transparency/translucency to match my navigation bar.
I've tried "solution" from How to change background color of UISearchBar in iOS7 but it doesn't work. Result of this solution looks like that:
searchDisplayController?.searchBar.barTintColor = UIColor.myAppRedColor()
searchDisplayController?.searchBar.translucent = false
As you can see - that isn't exactly matching Navigation Bar color. It also has a separator between navbar and search bar.
Next solution almost worked:
searchDisplayController?.searchBar.backgroundImage = UIImage()
searchDisplayController?.searchBar.backgroundColor = UIColor.myAppRedColor()
But when I tap on the search bar it changes color:
It also has very weird animation:
https://youtu.be/Dq1GKBGbmTc
Do you have an idea what else I can do instead of implementing my own SearchBar?
Do not use Search Display Controller. Instead use only searchBar and TableView.
Simply delete Search Display Controller from your storyboard.
You will receive delegate methods of searchBar.
Here you can apply search on tableView.

iOS 7 UITableView extends beneath UINavigationBar

Project Overview
I have a UITableViewController as the root view controller of a UINavigationController. Its view is a UITableView using the UITableViewStyleGrouped style. The table view also has a UIRefreshControl. I am not using nib/xib files, everything is created programmatically.
Problem
The header for the first section in my table view goes under the navigation bar. The refresh control, however, is in the right place. Normally problems with this are caused by a translucent navigation bar, but mine is opaque already.
Attempted Solutions
self.edgesForExtendedLayout = UIRectEdgeNone
This doesn't produce any changes.
self.tableView.contentInset = UIEdgeInsetsMake(20.0f, 0.0f, 0.0f, 0.0f);
This puts my table view in the right place, but causes the refresh control to be adjusted down as well. Not to mention that this is a dirty solution anyway.
Try using:
[self setAutomaticallyAdjustsScrollViewInsets:NO];
You need to use a plain viewcontroller and add the tableview there at the desired position.
This is because in case of an uitableviewcontroller the whole tableview is the parentview . I hope you got my point.

IOS Customizing UISearchBar and Search Display

Hey I have been trying to customize a UISearch bar with display controller and have run into some issues customizing certain aspects of the search and display controllers. I'm using storyboard and am developing with the most recent version of IOS 6.
The first issue is eliminating the dark grey gradient overlay that appears when you first click on the search text view. I have tried to use the searchDisplayController:willShowSearchResultsTableView: delegate but am unable to either find the view that is being used as the gradient overlay or a property to disable it. How do I remove this view?
The second is I am having an issue with the initial animation that is triggered when the search view is clicked. The animation is supposed to expand the search bar over the UINavigationBar to allow for a larger space to view the results. This doesn't happen and the search bar stays below the UINavigationBar and the animation doesn't properly show. I have tried setting the displaysSearchBarInNavigationBar and navigationItem properties but couldn't find any way to access or set them. Could this be an issue with the fact that I'm using autolayout in my story board? I have noticed that many issues relating to the UISearchBar animations are due to autolayout being used in the .xib or storyboard file. How can I make it correctly over the navigation bar?
The third issue I am having is with over ridding the searchBarTextDidBeginEditing:(UISearchBar *)searchBar delegate method. I have subclassed the UISearchBar to allow for complete customization. Is there a way to provide a default definition for the searchBarTextDidBeginEditing: delegate method inside my custom UISearchBar subclass. I want to provide a specific style of text in the UITextView when the user clicks on the search bar and don't want to have to redefine this method in every view controller that uses the search bar. Is this possible?
Thanks for the help in solving these issues.

Hide/show search bar with pressing a button

I have a tableview with a search bar. All is working fine but now I want a button to hide/show the search bar. This functionality is what my question is about.
Now I have created a bar below the screen where I have created a button for this. In code, there is a void function which can be filled with the code I am looking for. Just to give you an impression of how the code looks like. Right now it is empty.
I've done some research and I came up with bringSubViewToFront and sendSubViewToBack, HeadsUpUI sample app. The idea I had was that I could show the search bar by bringing it to front, put OVER the table view layer, while setting the tableview 44 pixels lower with content offset or so.
Likewise, sending the search bar layer to back, BEHIND the table view to hide it. So in the void function I tried something with [parentview sendSubViewToBack:child view] but to no effect. So my question is: how do I hide or show my search bar while having a table view and a navigation bar and a bar below with the button to do so?
Kind Regards,
John
Use like -
childview.hidden = YES;
EDIT 1-
childview.hidden = YES;
[parentview sendSubViewToBack:childview];
[tableView reloadData];
Hope it work for you.
You can use IBOutlate to your searchBar and then use this outlate to show or hide the search bar
Also don't forget to connect it with your searchBar in xib

Resources