iOS - How to display view or controller under UINavigationBar? - ios

I want to have a translucent navigation bar and display view or controller under it. Through the navigation bar, user can see the content display on the controller.But it always display from y=64 in iOS8. Do you know how to do it?

Put this code in applicationDidFinishLaunchingWithOption
//visible viewcontroller
[[UINavigationBar appearance] setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
//status bar
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
//One line pixel
[[UINavigationBar appearance] setShadowImage:[UIImage new]];

Related

remove border of navigation bar for few view controllers

I want remove border of navigation bar. I am using this code in AppDelegate.m
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init]
forBarPosition:UIBarPositionAny
barMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
and it works well. It removes border of navigation bar in every view controller.
But i have to remove it for few view controllers.
By placing this code in viewWillAppear of particular view controller, its not working.
Does anyone knows how to do it?
You should set the background image and shadow image of the navigation bar in your select navigations bars and not to use the appearance method. e.g.:
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];

How to push UITableview to under navigation bar?

I am working on a UI which has transparent navigation bar. I used this
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
[self.navigationController.navigationBar setTranslucent:YES];
Now I want the UITableView should start from top instead of offset like 64.
How to achieve that?
You can set it in storyboard or xib property panel.
Or you can do as below:
[self setAutomaticallyAdjustsScrollViewInsets:YES];
[self setEdgesForExtendedLayout:UIRectEdgeAll];
This should be done before viewWillAppear is invoked.

Mail app segue (open-with) with incorrect navigation bar colors

I am currently attempting to open up the iOS mail all to create a draft with an attachment generated from my app. Here is a code snippet:
NSURL *fileLocation = [NSURL fileURLWithPath:self.site.dataFileLoc];
if(fileLocation) {
self.documentController = [UIDocumentInteractionController interactionControllerWithURL:fileLocation];
[self.documentController setDelegate:self];
[self.documentController presentOptionsMenuFromRect:self.view.bounds inView:self.view animated:YES];
}
However, what I am finding is that the navigation bar colours are completely off. In the AppDelegate, I am currently using these lines to set the global navigation bar appearance:
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlack];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"navbarBackground"] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
[[UINavigationBar appearanceWhenContainedIn:[UIViewController class], nil] setShadowImage:[UIImage imageNamed:#"shadow"]];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];
[[UITabBar appearance] setTintColor:[UIColor whiteColor]];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
Unfortunately, the title of the mail view controller that appears is still black, despite my attempt to set the bar style to black (which should make the title white in return) and blue bar buttons. It does, however, seem to work fine for the "presentPreviewAnimated" view controller. How can I make the navigation bar of the mail view controller consistent?
Are there any nibs associated??
I usually try to avoid the desired level of UI customization (navigation bar styles, colors, custom background w/image) because drawing UI at runtime (unless dynamically required) generally gets me in trouble...
Why not mock it up in a .nib file and make use of the fancy-dance-y tools in Xcode?? Can be therapeutic to quickly obtain the desired grain of detail without having to hit run...

why Status bar and Navigation bar background colors are different in ios

I want to change background color of status bar and that background color should be same as navigation bar background color i.e dark gray color. My problem is after giving the same color for both status bar and navigation bar using my below code, i am getting the different color. I have already set UIViewControllerBasedStatusBarAppearance to NO. Please suggest me where i am doing wrong, i have attached below image for your reference.
here is my code of App delegate - didFinishLaunchingWithOptions:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//For changing status bar background color
self.window.backgroundColor = [UIColor darkGrayColor];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
//For changing navigation bar background color
[[UINavigationBar appearance] setBackgroundColor:[UIColor darkGrayColor]];
[[UINavigationBar appearance] setTintColor:[UIColor darkGrayColor]];
The reason they have different colors is because UIStatusBarStyleLightContent isn't the same color as [UIColor darkGrayColor].
If it's fine to adjust navigation bar color after how the status bar looks like, then you can set the status bar color:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
Find out the RGB values of the status bar. (For example, I use DigitalColor Meter, it says it has R:28, G: 28, B: 28).
Then you can do something like:
[[UINavigationBar appearance] setBackgroundColor:[UIColor colorWithRed:28/255.0 green:28/255.0 blue:28/255.0 alpha:1.0f]];
You might need to set translucency to NO.
If you only want it on certain screens, you can add this to the viewDidLoad method:
[self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:28/255.0 green:28/255.0 blue:28/255.0 alpha:1.0f]];
First Change the statusBar style in your VC's viewDidLoad method
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
And then change the BarTintColor to your desired color in your VC's viewDidLoad method
[self.navigationController.navigationBar setBarTintColor:[UIColor blackColor]];
In your AppDelegate's 'didFinishLaunchingWithOptions:' add following and it should work.
[[UINavigationBar appearance] setBarTintColor:[UIColor darkGrayColor]];

UINavigationBar custom background image applied in one view controller and then affecting every single view controller in the app

I am working with themes in my app. Each theme comes with a custom navigation bar. As a default, I have applied a custom navigation bar in my AppDelegate:
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
UIImage *navBackgroundImage = [UIImage imageNamed:#"purplynav.png"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];
If I go to a specific Table View Controller in my app and in the viewWillAppear, I put:
if ([self.selectedTheme isEqualToString:#"Blur"])
{
UIImage *navBackgroundImage = [UIImage imageNamed:#"pastelpinknav.png"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];
}
The "pastelpinknav" suddenly gets applied to every single navigation bar in my app, even though I'm only setting it in this one Table View Controller.
How do I set it so that the navigation bar only applies to this one view controller when set, but is still set to default in the App Delegate when a theme is not set?
Thanks in advance!
You have to change again the navigationBar image in viewWillDisappear
UIImage *navBackgroundImage = [UIImage imageNamed:#"purplynav.png"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];
Because you are using [UINavigationBar appearance] it will commonly changes the UINavigationBar appearance.
From your view controller call:
[[UINavigationBar appearanceWhenContainedIn:[self class], nil] setBackgroundImage:navBackgroundImage
forBarMetrics:UIBarMetricsDefault];
Explenation:
This will change the foo color of the entire app:
[[UINavigationBar appearance] setFooColor:#"blue"]
In order to change appearance of specific container (i.e your view controller), you need to implement UIAppearanceContainer and then call (UIViewController already implements it):
[UINavigationBar appearanceWhenContainedIn:(Class<UIAppearanceContainer>), ..., nil]

Resources