UISearchbar & SearchDisplay Controller not extending beneath status bar in iOS7 - iphone

I have a problem with a UISearchViewController (using a storyboard layout).
My main view controller has a navigation bar at the top, beneath which I have positioned the UISearchBar. A MKMapView extends below the search bar and navigation bar.
When the SearchViewController is active, the Navigation Bar slides up. I have added an autolayout constraint to stick the uisearchbar to the bottom of the nav bar. However, the search bar doesn't appear to extend beneath the status bar and above the map view. Instead the mapview appears in a 20px gap above.
Any help would be greatly appreciated!

Setting translucent to false on my navigation bar did not fix this. However setting the translucent property of my searchBar worked for me.
I used these UISearchDisplayDelegate methods to change the value depending on whether the searchBar is active or not.
func searchDisplayControllerWillBeginSearch(controller: UISearchDisplayController) {
// self.searchBar is an IBOutlet from storyboard
self.searchBar.translucent = false
}
func searchDisplayControllerWillEndSearch(controller: UISearchDisplayController) {
self.searchBar.translucent = true
}

I think it can be fixed with navigationBar.translucent = NO; It is set to YES by default in iOS 7. Had a lot of trouble with that myself.

Try this in info.plist file to disable the status bar

Related

Set status bar colour in Iphone

Hi I am developing small Iphone application in which I am giving colour for my navigation bar like this
[self.navigationController.navigationBar setTranslucent:NO];
[self.navigationController.navigationBar setBarTintColor:[UIColor redColor]];
But because of this my status bar also become of red colour. I want to change it to white. I tried in followings way but those are not working for me.
in info.plist file I set View controller-based status bar appearance = "NO"
then in application:didFinishLaunchingWithOptions: set [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
Then in UIViewcontroller
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
But above methods are not working for me. My navigation bar and status bar of same colour. I want to make status bar colour to white. My application is very simple having one UIView controller with one navigation controller. Am I doing some thing wrong? Need Help. Thank you .
UIStatusBarStyleLightContent tells the status bar to display light colored text, but it is still transparent. And because the navigation controller reports the position of its navigation bar to be UIBarPositionTopAttached, you see the effect of the navigation bar's color stretching beneath the status bar.
Here are two ideas how to achieve what you are looking for:
Subclass the navigation controller, implement - (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar and return UIBarPositionTop. This make the navigation bar not stretch beneath the status bar, and instead the superview of the navigation bar (which is usually white), will show.
Or, better, subclass the navigation controller, add a subview of 20pt height above the navigation bar, and in viewDidLayoutSubviews, position and resize the subview correctly to orientation. Now you can give any color you'd like to this view, and it will be the color of the status bar.
Edit: Based on the comments, the positionForBar: approach may not work.

iOS 7 TabBar Translucent issue

I have an issue, when I set the translucent box off on a TabBar, there is something blocking some of my view.
It looks like it's a sort of extra tab bar or I don't even know. I'm using storyboard.
Please see the images attached:
With Translucent (OFF - NO):
With Translucent (ON or YES):
Does anybody know why it looks like this?
Thanks
PS: Which tabBar do you guys like? Black or this one:
This happens in iOS7 when you set tabBar.translucent to NO. iOS is trying to be smart and say "hey the tabbar is not translucent so we better push everything up on top of it". Fix it by setting the extendedLayoutIncludesOpaqueBars property of the view controller inside the navigation controller which is inside the tabbar controller to YES.
Example (not actually ran):
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.tabBar.barStyle = UIBarStyleBlack;
tabBarController.tabBar.translucent = NO;
UIViewController *viewController = [[UIViewController alloc] init];
viewController.extendedLayoutIncludesOpaqueBars = YES; // <-- This is important!!!!!!
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController: viewController];
tabBarController.viewControllers = #[navigationController];
Source: https://web.archive.org/web/20160405135605/https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/AppearanceCustomization.html
And BTW, I like the non-translucent tabbar the best.
Edit
As Andy mentioned below, this flag does not have to be set in code. You can set it in IB if that's what you use.
As mentioned here you have to set barTintColor to something you want to change the color.
These settings automatically apply when you set any style for barStyle or any custom color for barTintColor. If you prefer, you can make the tab bar opaque by setting the translucent property to NO programmatically. In this case, the bar draws an opaque background using black if the tab bar has UIBarStyleBlack style, white if the tab bar has UIBarStyleDefault, or the tab bar’s barTintColor if a custom value is defined.
Something that I used for my project
self.tabBarController.tabBar.barTintColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0];
self.tabBarController.tabBar.translucent = NO;
I have acontroller with TableView and both translucent NavigationBar and translucent TabBar. In this situation using viewController.extendedLayoutIncludesOpaqueBars = YES; causes a problem of both bars overlaping my table view. It can be managed by setting viewController.edgesForExtendedLayout = UIRectEdgeBottom; which results in TableView hiding only behind Tab Bar.
It looks like you've set up the view controller's view so that its bottom is at the same position as the top of the tab bar, when it should be at the bottom of the screen. If you do that, then your content will appear correctly (content visible through the tab bar or not) whether the tab bar is set to translucent or not.
For those who actually want a translucent Tabbar and a table view (or collection view for me) that can be seen behind, here is my solution for ios 7/8:
If you are using constraints, you should add one on the bottom of the table view to the "Bottom Layout Guide" so your tableview stops before the Tabbar. This is an example with Storyboard, but it can be done in code as well.
Then you just need to make sure you can still see the table view behind the Tabbar by settings the "clipsToBounds" property to NO.
self.mytableview.clipsToBounds = NO;
This is my solution, hope it helps.
I don't think the currently accepted answer is correct. You don't need to extend the layout under opaque bars to solve the issue.
There is no code provided in the OP, but it is likely that the bottom of the view containing the items is constrained to the bottom of its superview, which would have taken the items underneath the translucent tab bar. To prevent this, a manual inset could have been set from the bottom. In short, the superview extends underneath the translucent bar and so did its subviews.
As soon as the tab bar was made opaque, the root view (or the superview) only extended until the top of the tab bar.
The 'more' correct fix would be to just remove the manual inset of content, not extending the view under opaque bars.

How do you make the UISearchBar translucent?

On iOS 7, setting the UISearchBar to be translucent isn't making the search bar translucent. Is there anything I'm not understanding it? I'm adding it to a UIViewController that is part of a UINavigationController. There's a UITableView aligning to the Top Layout Guide. The navigation bar is fine and has translucency, but the search bar is a solid color for some reason.
See the new .searchBarStyle property on UISearchBar. I suspect UISearchBarStyleMinimal is what you're after.

How to set the position of a Navigation Bar programmatically

How to set the position of a Navigation Bar programmatically? Autolay have been turned off as its causing issues in other IOS. Cheers guys.
[my layout]
View Controller
View
Toolbar
WebView
Navigation Bar
Nav Item
First Responder
Exit
Navigation bar is currently appearing at the bottom of the screen not the top where I want it.
Try this
[self.navigationController.navigationBar setFrame:CGRectMake(x,y,width,height)];
If you are using Interface Builder you can simply drag the navigation bar to where you want it

Navigation bar is translucent, but that is not what IB says

I think I must be going nuts here. I have a UINavigationController and in every view that I have pushed I have selected Black Navigation Bars in IB, but they all turn up as translucent ones.
What have I done wrong?
Thanks
Is the translucent property on the UINavigationBar set properly?
Check your code to see if translucent is set somewhere or add this to your VC to print out the value:
NSLog(#"navBar.translucent = %d",
(int)navController.navigationBar.translucent);
And check the Navigation Controller in IB, the Navigation Bar section should have a Style of Black Opaque (not Black Translucent), and an Alpha of 1.00.
Nav Bar in IB http://morrisphotoart.com/tmp/Screen%20shot%202010-04-20%20at%2005.43.26.png
Are you sure you are not re-declaring the color of the bar in code somewhere?