IOS7 navigatinBar tintColor change in popover - ios

I developed iPad application. I'm opening some screens in popover with navigation controller. But I did not change navigationcontroller tint color in IOS 7. How can I change this color. thanx
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:airportsSearch] autorelease];
navigationController.navigationBar.barTintColor = [UIColor blackColor];
navigationController.navigationBar.translucent = NO;
self.popOver=[[UIPopoverController alloc] initWithContentViewController:navigationController];
self.popOver.delegate = self;
[self.popOver setPopoverContentSize:CGSizeMake(285, 370)];
[self.popOver presentPopoverFromRect:tempButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];

The magical word here is barStyle, you need to do the following if you need it black:
navigationController.navigationBar.barStyle = UIBarStyleBlack;
navigationController.navigationBar.translucent = NO;
And if you want to change its color:
navigationController.navigationBar.barTintColor = [UIColor redColor];
navigationController.navigationBar.barStyle = UIBarStyleBlack;
navigationController.navigationBar.translucent = NO;

Setting the NavigationBarStyle to UIBarStyleBlack also worked for me, but only via the Storyboard.
I tried
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlack];
as well as
[[UINavigationBar appearanceWhenContainedIn:[UIPopoverController class], nil] setBarStyle:UIBarStyleBlack];
in the didFinishLaunchingWithOptions AppDelegate method. But nothing changed. Only changing the BarStyle of the NavigationControllers NavigationBar inside the Storyboard worked.

Related

Unable to set color of UIViewController navigation bar

I'm presenting my view controller with the following code:
UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:sessionController];
[self presentViewController:navigation animated:YES completion:^{
}];
from within the presented view controller "viewDidLoad" method I'm attempting to set the navigation bar color with the following, but I am not successful:
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
self.navigationController.navigationBar.backgroundColor = [UIColor blackColor];
self.navigationController.view.backgroundColor = [UIColor blackColor];
UINavigationBar.appearance.backgroundColor = [UIColor blackColor];
UINavigationBar.appearance.tintColor = [UIColor blackColor];
The navigation bar color will NOT change from white. Any advice would be much appreciated.
Note: I am not using story boards or XIB files.
Try the following code to change the background color:
[self.navigationController.navigationBar setBarTintColor:[UIColor blackColor]];
[self.navigationController.navigationBar setTranslucent:NO];
The navigation controller object create when applied the color. Like this below example.
UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:sessionController];
navigation.navigationBar.tintColor = [UIColor blackColor];
navigation.navigationBar.backgroundColor = [UIColor blackColor];
navigation.navigationBar.barTintColor = [UIColor blackColor];
[self presentViewController:navigation animated:YES completion:^{
}];
And below this method all navigation controller change color.
UINavigationBar.appearance.backgroundColor = [UIColor blackColor];
UINavigationBar.appearance.tintColor = [UIColor blackColor];

iOS: TabBar controller above UIView

I am having a problem with my tab bar placed above my view
I am using iOS 8 and Autolayout
I have my main view which has a button that opens another view that has the tab bar:
-(IBAction)btnOpen:(id)sender
{
Home* homevc = [[Home alloc] initWithNibName:#"Home_iPhone" bundle:nil];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:homevc];
[nc.tabBarItem setTitle:#"Home"];
[nc.tabBarItem setImage:[UIImage imageNamed:#"home_icon.png"]];
Search *searchvc = [[Search alloc] initWithNibName:#"Search_iPhone" bundle:nil];
[searchvc.tabBarItem setTitle:#"Search"];
[searchvc.tabBarItem setImage:[UIImage imageNamed:#"search_icon.png"]];
UITabBarController *tabController = [[UITabBarController alloc] init];
[tabController setViewControllers:[NSArray arrayWithObjects:nc,searchvc, nil]];
UIColor * color = [UIColor colorWithRed:191/255.0f green:50/255.0f blue:46/255.0f alpha:1.0f];
[[UITabBar appearance] setTintColor:color];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:color, NSForegroundColorAttributeName, nil]
forState:UIControlStateSelected];
[self presentViewController:tabController animated:YES completion:nil];
}
How can I place the Home view above the tab bar?

ios tabBarControl, navigationcontroller title and button editing

I've been using a standard TabBarController and top NavigationBar within my app. The tabBar loads in the appDelegate, initializes the navigationBar to use an image instead of center title, and this exists for all four tabBar views. Occasionally I'll push a new view onto the view controllers and that works well enough.
What I'd like to do is be able to change the NavigationBar for each of the 4 tabBar view controllers, when they are opened. I'm having trouble doing this. My initial navigationBar has an image, loaded in the appDelegate. My questions from here are:
Should each viewController generally create a new navigationBar from scratch, per its needs, in the respective viewWillAppear method?
What navigationController and navigationBar should be editted-- always the appDelegate's navigationController, the tabBarController.navigationController, or simply self.navigationController in each view? (generally, most editing most of these is not working for me, causes no changes to occur)
If I override the standard title (which is usually the tabBar's current view's title) with the imageView, and want another tabBar view to use the standard title, how should I remove the titleView image, and reset back to text? And viceVersa, dependent on view? This is what I'm really trying to accomplish unsuccessfully.
I guess I'm looking for standard practice in managing the navigationBar per view, and changing it per tabBarItem.
// in appDelegate
- (void)initNav {
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.delegate = self;
self.tabBarController.navigationController.view.backgroundColor = [UIColor whiteColor];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:self.firstViewController,
self.secondViewController,
self.thirdViewController,
self.forthViewController,
nil];
[self.window addSubview:self.tabBarController.view];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.tabBarController];
self.navigationController.navigationBarHidden = NO;
// customize background color of nav bar to "blue"ish color
self.navigationController.navigationBar.backgroundColor = [UIColor colorWithHexString:#"00A3E1"];
self.navigationController.navigationBar.tintColor = [UIColor colorWithHexString:#"00A3E1"];
self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:#"00A3E1"];
[self createNavs];
}
// also in appDelegate
- (void)createNavs {
// white text when present
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],
UITextAttributeTextColor,
[UIColor clearColor],
UITextAttributeTextShadowColor, nil];
[[UIBarButtonItem appearance] setTitleTextAttributes: attributes
forState: UIControlStateNormal];
AppDelegate *delegateRef = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[self.navigationController.navigationBar setTranslucent:NO];
// setup left button (currently unused -- no left button)
/*
/*
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:#"glyphicons_049_star.png"] forState:UIControlStateNormal];
[button addTarget:self action:#selector(starClick:) forControlEvents:UIControlEventTouchDown];
[button setFrame:CGRectMake(0, 0, 25, 25)];
self.navigationController.navigationBar.topItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
*/
// setup logo in center
self.tabBarController.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"synced_top_logo.png"]];
// setup right button (currently unused -- no right button)
/*
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] init];
rightButton.title = #"edit";
[rightButton setTarget:self ];
[rightButton setAction:#selector(editClick:)];
self.navigationController.navigationBar.topItem.rightBarButtonItem = rightButton;
*/
[[self navigationController] setNavigationBarHidden:NO animated:YES];
[[delegateRef navigationController] setNavigationBarHidden:NO animated:YES];
}
EDIT:
This is a simplified version of the solution posted below that was helpful, and allowed the customization that was needed. Each view controller customizations its navigationbar independently from this. It was probably how it should have been done from the start.
tabBarController.viewControllers = [NSArray arrayWithObjects:[[UINavigationController alloc] initWithRootViewController:self.firstViewController],
[[UINavigationController alloc] initWithRootViewController:self.secondViewController],
[[UINavigationController alloc] initWithRootViewController:self.thirdViewController],
[[UINavigationController alloc] initWithRootViewController:self.forthViewController],
nil];
This maybe what you are needing:
- (void)initTabbar {
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.delegate = self;
/*
You want each of your UIViewControllers to be wrapped in a UINavigationController. Then put each of those UINavigationControllers in a UITabBarController
*/
//You don't need to hang on to this becuase the proceeding UINavigationController will handle it
FirstViewController *firstViewController = [[FirstViewController alloc] ...];
//You'll need to declare this in your header
self.firstNavigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
//Second view allocation
SecondViewController *secondViewController = [[SecondViewController alloc] ...];
self.secondNavigationController = [[UINavigationController alloc] initWithRootViewController:secondViewController];
//Third view allocation
ThirdViewController *thirdViewController = [[ThirdViewController alloc] ...];
self.thirdNavigationController = [[UINavigationController alloc] initWithRootViewController:thirdViewController];
//Now you add each of the UINavigationControllers (which is a subclass of UIViewController) to the UITabBarController.
self.tabBarController.viewControllers = [NSArray arrayWithObjects:self.firstNavigationController,
self.secondNavigationController,
self.thirdNavigationController,
nil];
[self.window addSubview:self.tabBarController.view];
[self createNavs];
}
//This is more of a 'formatNavs' now
- (void)createNavs {
//Now you can customize each of the UINavigationController's UINavigationBars seperatly
self.firstNavigationController.navigationBar.backgroundColor = [UIColor colorWithHexString:#"00A3E1"];
self.firstNavigationController.navigationBar.tintColor = [UIColor colorWithHexString:#"00A3E1"];
self.firstNavigationController.navigationBar.barTintColor = [UIColor colorWithHexString:#"00A3E1"];
self.secondNavigationController.navigationBar.backgroundColor = [UIColor colorWithHexString:#"...."];
self.secondNavigationController.navigationBar.tintColor = [UIColor colorWithHexString:#"...."];
self.secondNavigationController.navigationBar.barTintColor = [UIColor colorWithHexString:#"...."];
self.thirdNavigationController.navigationBar.backgroundColor = [UIColor colorWithHexString:#"...."];
self.thirdNavigationController.navigationBar.tintColor = [UIColor colorWithHexString:#"...."];
self.thirdNavigationController.navigationBar.barTintColor = [UIColor colorWithHexString:#"...."];
}

UISearchBar not displaying correct tintColor

If i add my UISearchBar without referencing it to a UISearchDisplayController, my tintColor is displayed correctly.
searchBar.barTintColor = [UIColor colorWithRed:200.0f/255.0f green:21.0f/255.0f blue:26.0f/255.0f alpha:1.0f];
But if i reference my UISearchBar to a UISearchDisplayController the color seems different...
searchBar = [[UISearchBar alloc] init];
[searchBar setBarTintColor:[UIColor colorWithRed:200.0f/255.0f green:21.0f/255.0f blue:26.0f/255.0f alpha:1.0f]];
searchBar.delegate = self;
searchBar.searchBarStyle = UISearchBarStyleProminent;
searchBar.placeholder = #"Buscar restaurantes o platillos";
searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
searchController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
searchController.delegate = self;
self.tableView.tableHeaderView = searchBar;
My tintColor settings on my AppDelegate are
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:200.0f/255.0f green:21.0f/255.0f blue:26.0f/255.0f alpha:1.0f]];
[[UINavigationBar appearance] setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor whiteColor]}];
[[UIToolbar appearance] setBarTintColor:[UIColor colorWithRed:200.0f/255.0f green:21.0f/255.0f blue:26.0f/255.0f alpha:1.0f]];
self.window.tintColor = [UIColor whiteColor];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
self.window.backgroundColor = [UIColor colorWithRed:200.0f/255.0f green:21.0f/255.0f blue:26.0f/255.0f alpha:1.0f];
Besides that also when my UISearchBar is referenced to my UISearchDisplayController and i tap on the search field... on the transition the background of the Status bar is white.
Any ideas?
i'm Using iOS7
Thanks in advance!
you can set image in searcher. It will work for searchbar.
[[UISearchBar appearance] setBackgroundImage:[UIImage imageNamed:#"red"]];
Try setting the translucent property to no.
[[UISearchBar appearance] setTranslucent:NO];
I found that solution working on iOS7+
searchBar.backgroundImage = UIImage()
searchBar.tintAdjustmentMode = UIViewTintAdjustmentMode.Normal
searchBar.barTintColor = Utils.tintColor()
For UISearchController in Swift use:
searchController.searchBar.barTintColor = UIColor.whiteColor()

Presented UINavigationController tint color not changing

MyVC *vc = [[MyVC alloc] init];
vc.delegate = self;
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc];
[nc.navigationBar setTintColor:[UIColor redColor]];
[self presentViewController:nc animated:true completion:^{}];
The navigation bar is black. I present this from a navigation controller inside a tab bar controller which is created in my App Delegate. In my ApplicationDidFinishLaunchingWithOptions, I can control the color of the navigation controllers there.
Why is this navigation controller tint bar black?
[[UINavigationBar appearance] setTintColor:[UIColor redColor]];
I would suggest you to use this if all of your NavigationBars are the same color. Appearance property of an object sets uniformity on the function you apply on it.
You can try to make custom class for UINavigationBar
.h
#interface CustomUINavigationBar : UINavigationBar {
}
#end
.m
#implementation CustomUINavigationBar
- (void)drawRect:(CGRect)rect {
UIColor *color = [UIColor colorWithRed:0.023 green:0.14 blue:0.478 alpha:1];// for example
self.tintColor = color;
}
#end
Also you can try to insert the below code in the didFinishLaunchingWithOptions: of AppDelegate.m
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
In iOS7 you have to use barTintColor property
[nc.navigationBar setBarTintColor:[UIColor redColor]];
instead of
[nc.navigationBar setTintColor:[UIColor redColor]];

Resources