I have added the UIActivityViewController in the contentView of UIPopoverController. And trying to open Print Option which is navigating in UIPopoverController itself. I am getting that view
And I am getting the color of Title (Print Options / Printer) and back button is white , I want it to blue.this is only in case of UIPopoverController. Otherwise al is fine.
Please suggest !!!
For the Title use:
[self.navigationController.navigationBar setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor blueColor]}];
For the arrow and text of back button:
[self.navigationController.navigationBar setTintColor:[UIColor blueColor]];
And of course if you have an object of UIPopoverController you have to apply the styles from navigation bar:
popoverController.navigationBar.titleTextAttributes = self.navigationController.navigationBar.titleTextAttributes;
In your viewDidLoad method for that controller:
for (UIView *subview in self.navigationController.navigationBar.subviews) [subview setTintColor:[UIColor blueColor]];
Related
I present a modal view when I click a cell in my custom tableview. How to change the background color of navigation bar in a modal view?
For example. I want to change it to black color.The following code do not work in the prepare segue method.
[destinationNavController.navigationBar setBackgroundColor:[UIColor blackColor]];
or
[[UINavigationBar appearance]setBackgroundColor:[UIColor blackColor]];
or
[destinationNavController.navigationBar setTintColor:[UIColor blackColor]];
in the viewDidLoad method of the destination Controller view I write
[self.navigationController.navigationBar setBackgroundColor:[UIColor blackColor]];
or
[[UINavigationBar appearance]setBackgroundColor:[UIColor blackColor]];
or
[self.navigationController.navigationBar setTintColor:[UIColor blackColor]];// only change the navigation item text color....
Any other ideas?
This the right way to present the modal controller and change the nav bar color, write the below code:-
[self presentModalViewController:customViewController animated:YES];
customViewController.topViewController.navigationController.navigationBar.tintColor = [UIColor blackColor];
If you are on ios 7 or later, you need to use the barTintColor property of UINavigationBar.
Like this:
self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
I only tested this in iOS 11 so far and in my case our app is white but I want to present a fullscreen slide show with black color, but I still wanted a status bar, with white letters and the same black background as my main view
Step 1: make your view background color black.
XCode in your .xib or storyboard the parents view's background color black (very important step)
Step 2:
in your view controller that is in charge of this view, add this:
override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent }
This makes the color of the status text to be white. This also works on iPhone X.
I have a question for you about navigation bar transparency.
Here a screenshot of my view:
It's just a UIWebView embedding an HTML page.
I want to make visible the web page under the navigation bar by transparency, but I don't know how to make that.
I've already add self.navigationController.navigationBar.translucent = YES; to the viewDidLoad method, but when I scroll the web page, nothing is visible by transparency.
How I can place the UIWebView frame under the navigation bar, but not the web page ?
Try this
[self.navigationController.navigationBar setBackgroundColor:[UIColor clearColor]];
[self.navigationController.view setBackgroundColor:[UIColor clearColor]];
[self.navigationController.navigationBar setBarTintColor:[UIColor clearColor]];
Do you use your own custom made navigation controller or interface builder? Sometimes I have the same problem with settings in interface builder.
I find how to make that. Just add this in the viewDidLoad method :
self.navigationController.navigationBar.alpha = 0.8f;
self.navigationController.navigationBar.translucent = YES;
Note, I've recently come back to this and it seems to have been fixed in more recent versions of the SDK, without me having to implement anything except the code in the question. Many thanks to all who answered.
I have an Objective-C app that runs on the iPad and displays a view controller with a modal presentation style of UIModalPresentationPageSheet:
UINavigationController *editorNavigationController = [[UINavigationController alloc] initWithRootViewController:editorViewController];
editorNavigationController.modalPresentationStyle = UIModalPresentationPageSheet;
[navigationController presentViewController:editorNavigationController animated:YES completion:nil];
When this view controller is displayed the buttons in the navigation bar are purple, which I assume has been picked up from the window's tint colour, which is what I want.
Later I need to display another view controller over the top, that fills the whole window:
UINavigationController *previewNavigationController = [[UINavigationController alloc]initWithRootViewController:myPreviewViewController];
[owningViewController presentViewController:previewNavigationController animated:YES completion:nil];
The problem I have is that when myPreviewController is displayed, the buttons in the navigation bar are grey. I've tried reinstating the colour on the new navigation controller:
previewNavigationController.navigationBar.tintColor = [UIColor colorWithRed:123/255.0 green:26/255.0 blue:69/255.0 alpha:1];
but without any joy.
How can I get the buttons to have the correct colour? Can I get the new navigation controller to pick up the window tint colour automatically, or do I have to set it explicitly? Is this something to do with presenting the second navigation controller over the top of one that uses UIModalPresentationPageSheet?
Any help much appreciated! Thanks,
Paul
You can set the navigationBar translucent and transparent.
In view Will Appear:
self.navigationController.navigationBar.translucent = NO;
Than create a UIView with frame size of navigationBar (CGRectMake(0,0,self.view.frame.size.height,22) and create buttons on it with color you need.
I know, thats a crutch but should work)
You can change the appearance of the UIBarButtonItem globally so all UINavigationControllers will share the same design:
[[UIBarButtonItem appearance] setTintColor:[UIColor purpleColor]];
[[UIBarButtonItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:#"fontName" size:16.0f],NSFontAttributeName,
nil] forState:UIControlStateNormal];
Additionally you could also change the [UINavigationBar appearance]:
//The setTintColor would tint the < Back button in the NavigationBar
[[UINavigationBar appearance] setTintColor:[UIColor greenColor]];
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
[[UINavigationBar appearance] setTitleTextAttributes:
#{NSForegroundColorAttributeName:[UIColor blueColor]}];
This code can be add it before presenting the UIViewControllers or simply in the AppDelegate.m.
When i am trying to change the navigation bar tintcolor in split view the masterviewcontroller's navigationbarcolor chenged but detailviewcontroller navigation bar color not chenged. here is my code :
[[UINavigationBar appearance] setBarTintColor:[UIColor blueColor]];
[self.navigationController popViewControllerAnimated:YES];
i want to change the navigation bar color throughout the application in iOS7 by clicking on a button can any one help me?
You can simply do it by:
yourDetailViewController.navigationBar.barTintColor = [UIColor blueColor];
I am using a cocoa iOS component from cocoacontrols.com, which is NOT using storyboards. This class creates a new modal view and the modal view has a NavigationBar at the top. I am trying to get the color of the navigationBar to change. In all my other views, which are storyboard based, I use a base class of STBaseViewController which sets the navigationBar as white.
I have changed this cocoacontrol class to be a STBaseViewController instead of a UIViewController, but it still is not changing my background to white.
#interface BZPasscodeFieldController : STBaseViewController
In the BZPasscodeFieldController, which they don't make any reference to a navigationbar, so I am not sure how its even showing up (again it has no storyboard's only xibs and they don't have navigationbars)?
Anyway, does anyone know how to make the navigationbar background color white programatically?
Further, in all my storyboard viewControllers that have a UINavigationBar, I have added a UIButton over the area where the title goes, so that I can easily change the font/style and also make it clickable. I need to add this same UIButton to the uinavigationBar of this BZPasscodeFieldController created programatically. How would I go about doing that?
To Set Navigationbar Background Color:
[[UINavigationBar appearance] setBarTintColor:[UIColor orangeColor]];
To set Navigationbar Tint Color:
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
For your question about the button on the place of title of navigationBar. Each navigationBar has a titleView property, you can assign any view to it. For example take a look at this method, you can call it in your BZPasscodeFieldController:
- (void) setNavigationBarTitleButton
{
UIButton* centralButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 44)];
[centralButton setImage:navigationCentralButtonImage forState:UIControlStateNormal];
[centralButton setShowsTouchWhenHighlighted:TRUE];
[centralButton addTarget:self action:#selector(goHigher) forControlEvents:UIControlEventTouchDown];
self.navigationItem.titleView = centralButton;
}
For your previous question the answers provided already are all correct, calling them in the right place(for example in AppDelegate's application:didFinishLaunchingWithOptions: should make it work well, unless something is messed up in your custom view controller classes.
[[UINavigationBar appearance] setTintColor:[UIColor blueColor]];
[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];