Set status bar colour in Iphone - 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.

Related

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.

UISearchbar & SearchDisplay Controller not extending beneath status bar in iOS7

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

Change color of navigation buttons of default mail composer

I have used navigation bar category to color my navigation bar. All works fine.
But when I add mail composer picker, navigation bar gets coloured but buttons are default blue.
How can I change those?
I have used image in navigation bar in category.
mailer.navigationBar.tintColor = [UIColor yourColor];
This might help you :)

20px gap between top of ImageView and bottom of status bar after returning from iAd animation [duplicate]

What is the proper way to implement the status bar and navigation bar that go on top of an UIView?
alt text http://img.skitch.com/20081217-t78sdixk37hqgdh1ia2fgec4st.png
Just set “wants fullscreen layout” in your view controller. That solves the problem for me.
self.wantsFullScreenLayout = YES;
In the screenshot above, there's a translucent status bar and a translucent navigation bar.
The status bar is set using
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackTranslucent];
The navigation bar is set using
theNavigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
If you have a view controller inside a navigation controller, and you want to hide the status bar in order to have your viewController's view in full screen, you can always call :
[self.navigationController.view setNeedsLayout];
after hiding the status bar.
But I personally think
[self setWantsFullScreenLayout:YES];
is a better way.
The best way I came up was this: when using a "complex" hierarchy of Tab bar containing navigation controllers, with one "detail" view being a full screen view.
In the app delegate just before the tab bar controller's view is added to the window, I added this:
tabBarController.view.frame = [[UIScreen mainScreen] bounds];
This will make the tab bar controller cover the entire screen, even below the area of the status bar. I had to offset heights of several views to +20px, notably the navigation bars.
Set the statusbar style as black translucent and navigation bar style as black translucent. If you are using a navigation-based application, in the MainWindow.xib check the status bar is hidden and navigation bar is hidden checkboxes.
When the user touches the screen, start a timer to see if this was a single tap or double tap. If a single tap, make the statusbar and navbar hidden = NO. and once user activity stops, start a timer again. after some time of no activity, make them hidden again.
step 1 Set the UIViewControllerBasedStatusBarAppearance to No in the plist
Then add the following code in did finish launch option
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
[application setStatusBarStyle:UIStatusBarStyleLightContent];
self.window.clipsToBounds =YES;
self.window.frame = CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
}
Please follow this code it worked for me

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?