navigation controller bar is being cut off - ios

If hiding the status bar by choosing status bar style = hide during application launch and I am customizing uinavigation bar like the following
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed: #"navbar-iphone.png"]
forBarMetrics:UIBarMetricsDefault];
and when I am getting this : the navigation bar is cut off the top.
and
Any ideas about this situation and how to fix it ?

You can try this.
during application launch. here viewController is UINavigationController.
//set status bar hidden true.
[[UIApplication sharedApplication]setStatusBarHidden:YES];
//You can set navigation bar frame to start from 0.0,0.0
self.viewController.navigationBar.frame = CGRectOffset(self.viewController.navigationBar.frame, 0.0, -20.0);
//set the image u want.
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed: #"navbar-iphone.png"]
forBarMetrics:UIBarMetricsDefault];
Or
[[UIApplication sharedApplication]setStatusBarHidden:YES];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed: #"navbar-iphone.png"]
forBarMetrics:UIBarMetricsDefault];
[self.viewController setWantsFullScreenLayout:YES];

Related

iOS Make Navigation Bar transparent, while at the same time, preventing view to slide under Navigation Bar

My problem is, when I set the navBar to transparent with this code:
[[self navigationController] setNavigationBarHidden:NO animated:YES];
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
[self.navigationController.navigationBar setTranslucent:YES];
.. the navigationbar hides the top of the viewcontroller's view:
I tried to prevent this with:
self.edgesForExtendedLayout = UIRectEdgeNone;
... but then, the navbar is not transparent anymore.
How can I achieve both?

Double Navigation Bar when I set translucent to NO

When i set this code in viewDidLoad:
[self.navigationController.navigationBar setTranslucent:NO];
and run the project in xcode, it creates other nav bar above of my main nav bar.
Anyone know what is it?
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.view.backgroundColor = [UIColor clearColor];
The code above set the nav bar from translucent to solid without hide or create an other nav bar.

DocumentInteractionController Navigation Bar Color

In my iOS application, I am using the DocumentInteractionController to preview the .csv document.
self.documentController = [UIDocumentInteractionController interactionControllerWithURL:fileLocation];
[self.documentController setDelegate:self];
[self.documentController presentPreviewAnimated:YES];
However, I am finding that the navigation bar is completely transparent. The back button is white, so it is not visible due to the white background.
Note that I have styled the navigation bar in the AppDelegate:
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0/255.0f green:138/255.0f blue:188/255.0f alpha:1.0f]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTitleTextAttributes:#{NSFontAttributeName:[UIFont fontWithName:#"DINPro-Bold" size:17]}];
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[UIImage imageNamed:#"shadow"]];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];
[[UITabBar appearance] setTintColor:[UIColor whiteColor]];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
Essentially, my question is how can I make the appearance of the navigation bar in the DocumentInteractionController View Controller consistent with the appearance of the navigation bar throughout the entire app (or at least visible!).
This line puts a transparent (or rather void) background image to your UINavigationBar. Why is that?
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
Just remove the line and everything works well.
If you want to set a shadow image, then you should think about using appearanceWhenContainedIn: instead of appearance so it won't spread to unhandled controllers.
As for the Status Bar Style, the simplest way would be to pass self.navigationController as the presenter, instead of self:
- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller {
return self.navigationController;
}
Hope this will help,

how to remove separator between Navigation bar and Status bar - iOS 6

I am giving the same background color for both Navigation bar and Status bar for ios 6 using my below code. But i don't know why i am getting 1 pixel of separator line as i have mentioned in my attached screenshot. Can you please help me how can i remove this line?
here is my code for App Delegate:
//For changing status bar background color
self.window.backgroundColor = [UIColor colorWithRed:(51/255.0) green:(51/255.0) blue:(51/255.0) alpha:1.0]];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
//For changing navigation bar background color
[[UINavigationBar appearance] setBackgroundColor:[UIColor colorWithRed:(51/255.0) green:(51/255.0) blue:(51/255.0) alpha:1.0]];
[[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:(51/255.0) green:(51/255.0) blue:(51/255.0) alpha:1.0]];
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
Thanks in advance.

Revert navigation bar's background image to default

At first, I set navigation bar's background to translucent.
barImage=[[self.navigationController.navigationBar backgroundImageForBarMetrics:UIBarMetricsDefault] copy];//barImage is a UIImage point
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
It works well.
Now I need to revert navigation bar's background image to default.
- (void)dealloc
{
[self.navigationController.navigationBar setBackgroundImage:barImage
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = nil;
}
This doesn't work. What should I do?
Not sure if you're still stuck on this, but here's the code to reverse the effect. I borrowed a navigation controller, and copied everything over to the original navigation controller.
UINavigationController *tempNavigationController = [[UINavigationController alloc]initWithRootViewController:[[UIViewController alloc]init]];
[self.navigationController.navigationBar setBackgroundImage:[tempNavigationController.navigationBar backgroundImageForBarMetrics:UIBarMetricsDefault]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [tempNavigationController.navigationBar shadowImage];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.view.backgroundColor = tempNavigationController.view.backgroundColor;
tempNavigationController = nil;

Resources