Overlaps the status bar on view iOS7 - iphone

I have develop the my iPad application in ios6 but now i want to develop that application in ios7 also , I am using .xib file and I am not using the AutoLayout i want to use the black status bar in my application and i want to make the application similar like ios 6 but the status bar is overlap on the view i use the different code like below link
Link 1
Position of navigation bar for modal view - iOS7
Link 2
iOS 7 - Status bar overlaps the view
Thanks in Advance

wont happen, two options:
use a custom background image that is sized accordingly.. IIRC 44 (for navbar) + 20 (for status bar)
OR
account for the 20 pixels by using a custom view which is black :D

In iOS 7, the status bar is transparent, and other bars—that is, navigation bars, tab bars, toolbars, search bars, and scope bars—are translucent. As a general rule, you want to make sure that content fills the area behind the bars in your app.
Because the status bar is transparent, the view behind it shows through. The style of the status bar refers to the appearance of its content, which includes items such as time, battery charge, and Wi-Fi signal. Use a UIStatusBarStyle constant to specify whether the status bar content should be dark (UIStatusBarStyleDefault) or light (UIStatusBarStyleLightContent):
UIStatusBarStyleDefault displays dark content. Use when light content is behind the status bar.
UIStatusBarStyleLightContent displays light content. Use when dark content is behind the status bar.
In some cases, the background image for a navigation bar or a search bar can extend up behind the status bar. If there are no bars below the status bar, the content view should use the full height of the screen.
In iOS 7, you can control the style of the status bar from an individual view controller and change it while the app runs. If you prefer to opt out of this behaviour and set the status bar style by using the UIApplication statusBarStyle method, add the UIViewControllerBasedStatusBarAppearance key to an app’s Info.plist file and give it the value NO.
For more details about how to use status bar with navigation controller, please refer my answer here.

Try below to do not overwrite status bar:
[navController.navigationBar setBackgroundImage:[UIImage imageNamed:#"navBar.png"] forBarPosition:UIBarPositionTop barMetrics:UIBarMetricsDefault];

A workaround to use the old style status bar is to modify the frame of the main view and shift it down 20px. This will only work on viewWillAppear function but you need to make sure you call this once. This is more of a hack than a solution:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.view setFrame: CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y+20, self.view.frame.size.width, self.view.frame.size.height-20)];
}

Related

UIStoryBoard - Prevent View from overlapping status bar (iOS 11 App)

I want to stop overlapping of my View with statusbar
Use Auto Layout and pin your view to Top Layout Guide, or use the new Safe Area Layout Guides. To enable it, in your storyboard's File inspector tick the following option.
As an example I have used gray image view:
As you can see below, it does not overlap status bar:

Navigation bar appear over the views with new iOS7 SDK

CGRect cgRect1 = [[UIScreen mainScreen] applicationFrame];
UISearchBar *mySearchBar = [[UISearchBar alloc]
initWithFrame:CGRectMake(0, 0, cgRect.size.width, 40)];
mySearchBar.autoresizingMask =
UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight ;
UITableView *myTableView = [[UITableView alloc]
initWithFrame:CGRectMake(0, 40, cgRect.size.width, cgRect.size.height-40)];
myTableView.autoresizingMask =
UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
[self.view addSubview:mySearchBar];
[self.view addSubview:myTableView];
In the earlier versions it is working correctly. The search bar is appearing below the statusbar and navigation bar. The tableview is appearing below the search bar
But when I run this on Xcode 5 sdk iOS 7, the search bar is not visible (I think its placed under the status bar and navigation bar) , and also the navigation bar is appearing over the table view.
Will it be fixed with iOS 7 stable release ?
Or is it the problem of my coding ?
Or should we handle it by adding the y (y = statubar height + nav bar height) value for iOS 7 ?
I recently downloaded Xcode 5 DP to test my apps in iOS 7. The first thing I noticed and confirmed is that my view's bounds is not always resized to account for the status bar and navigation bar.
In viewDidLayoutSubviews, I print the view's bounds:
{{0, 0}, {320, 568}}
This results in my content appearing below the navigation bar and status bar.
I know I could account for the height myself by getting the main screen's height, subtracting the status bar's height and navigation bar's height, but that seems like unnecessary extra work.
Has anyone else experienced this issue?
UPDATE:
I've found a solution for this specific problem. Set the navigation bar's translucent property to NO:
self.navigationController.navigationBar.translucent = NO;
This will fix the view from being framed underneath the navigation bar and status bar.
However, I have not found a fix for the case when you want the navigation bar to be translucent. For instance, viewing a photo full screen, I wish to have the navigation bar translucent, and the view to be framed underneath it. That works, but when I toggle showing/hiding the navigation bar, I've experienced even stranger results. The first subview (a UIScrollView) gets its bounds y origin changed every time.
That’s not entirely true. There has been a new property introduced in iOS 7 that lets you adjust the layout behavior as in previous versions of iOS. Place this piece of code in your view controller, and you should be good to go! The space your navigation bar takes up should be accounted for automatically
if ([self respondsToSelector:#selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
You need add the above in your -(void)viewDidLoad method.
Note: You should be using the latest GM release of iOS 7 and Xcode 5 now since the API has changed from beta versions.
If you are working in Storyboard (which I strongly recommend!) this is the solution:
You can disable "Extend Edges" of your ViewController in storyboard. You have to do this for each viewController. You can disable extended edges by clicking the viewController icon in stortyboard (besides the productOwner beneath the view itself) and then selecting the attributes inspector (Like the images shows).
This will also set the alignment lines like iOS 6.
Another great tool in xCode 5 is "Preview": click on the butler Button (assistant editor) and select Preview. there you can select iOS 6 and see how your storyboard design will look like on iOS 6.
Its just great:D
[Update]
Be careful: disabling "Extend Edges" might result in a black glow on the navigation bar when the app enters background on iOS7. the glow will also be visible on the multitasking view (double press on home button). this can be solved by setting the background color of the navigation's bar view to white.
[self.navigationController.view setBackgroundColor:[UIColor whiteColor]];
As the OP says, there is a simple solution to this which is to set the navigation bar to be opaque. Rather than doing this in code, simply untick "Translucent" for your root navigation bar:
self.edgesForExtendedLayout=UIRectEdgeNone;
It works on iOS 7 simulator(Xcode 5 DP5)
these answers were all helpful, especially MQoder's, but for me i also had to set the default top bar to "opaque black navigation".
#One Man Crew's answer is correct, but:
I would recommend to use this code to avoid errors when running the app on older versions :
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1
if ([self respondsToSelector:#selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
#endif
self.edgesForExtendedLayout = UIRectEdgeNone;
And you need to do this on AppDelegate#application:didFinishLaunchingWithOptions:
self.window.backgroundColor = [UIColor whiteColor];
Otherwise Navigation Bar's background color will changed to gray. Because the transparent Navigation Bar overlaps window.
If you want to keep the transparency when the user scrolls your table view, you can set the contentInset of it:
CGFloat topLayoutGuide = self.topLayoutGuide.length + self.tabBarController.navigationController.navigationBar.frame.size.height;
self.tableView.contentInset = UIEdgeInsetsMake(topLayoutGuide, 0, 0, 0);
One solution is to use Navigation Controller. This automatically solve the issue.
Also use Xcode 5 instead of Xcode Preview versions since they are beta ones.

How to make tableview's content displayed under a transparent navigation bar?

How to make tableview's content displayed under a transparent navigation bar?
Like this:In "Photos" app, albums displayed under navigation bar.
Special thanks
If you use _rootNavigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent; then set correct tableview frame thats it. If you are in xib dont forget to simulate the translucent navigation bar.
One way I have found to accomplish this is by shifting your tableview's superview up to have the origin at {0, 0}. However after researching more several people have said altering the superview (UIViewControllerWrapperView) is a bad idea. However I also have not found any information on why just changing the frame would create problems. I am shifting the superview right now and haven't found any problems related to it yet.
Might be you can set it like this:
[navigationBar setAlpha:0.5f];
For making the navigation bar transparent alone, you can check this post, How to make a Navigation bar transparent and fade out like in the photo app in the iPhone
Also check this How to set the transparency color for Toolbar and Navigation bar using MonoTouch?
I am not sure whether you can add the table view behind the navigation bar. You might have to add it as a subview of self.parentViewController.view.
Another way to do this is by hiding navigation bar and using a transparent tool bar in place of that. This can be added on top of the current view. The only problem is with the back button. You might have to use custom button for that.

iPad style navbar on iPhone app

Hey, on iPad the navigation bar is normally silver and on the iPhone it's normally blue. Is there any easy way to make the silver navbar on iPhone app?
Thanks!!
If you just want to change the color of your navigation bar, the easiest way to do this would be to add your navigation bar in IB, then click on the navigation bar's attributes panel. Change the tint color to whatever color you would like in there and it will show up accordingly on your app. Similarly, if you are adding the navigation bar programmatically, you should be able to set the tint color yourself with something along the lines of myNavBar.tintColor = [UIColor someColor];. I hope this helps.
As of iOS 5 this can be easily achieved without any manual tinkering. Read this up.

How to set the Transparent statusbar in iphone

In my application i want to set the statusbar transparent.There are three styles are possible for changing the style of the statusbar.
gray
black
black translucent
mycode:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
How to set the transparent statusbar?
The best solution for this problem is to set self.wantsFullScreenLayout = YES; in your view controller and [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; for your status bar.
UPDATE:
As Mihir Oza told in comments the UIStatusBarStyleBlackTranslucent constant from old version of my answer is now deprecated. Use UIStatusBarStyleLightContent instead.
For the global app in the info.plist add Status bar style: Transparent Black Style (alpha 0.5).
The best way of doing this is with info.plist. Have a look at Apple's UIKit pList keys, specifically UIStatusBarStyle (and the value UIStatusBarStyleBlackTranslucent) for making it translucent, or the UIStatusBarHidden key (for hiding it totally).
It's not possible to make the status bar transparent. There are only 3 possible styles (gray, black and black translucent) you can set and you cannot get the bar's UIView.
However if you have static content behind it (i.e. a fixed part of your UI that you can edit) you can set the status bar to black translucent and add a 50% white layer just behind the bar. This makes the bar appear to be transparent.
Here's an example of what I mean.
See an example http://cl.ly/7WST/Untitled-1.png
In the info.plist set status bar style Transparent black style (alpha of 0.5).
In viewcontroller.xib set size fullscreen and status bar none.
In viewcontroller.m add following codes in viewWillAppear:
self.view.frame = CGRectMake(0,0,320,480);
This worked for me.
You can only hide the status bar using Status bar is initially hidden property in your info.plist