How I can see my webView under Navigation Bar by transparency? - ios

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;

Related

Show transparent UINavigationbar will see black bar when swipe the viewController

I have a UINavigationController with 3 viewControllers. We know the three viewControllers share a common navigationBar.If I want to set the navigationBar totally transparent. I can put the code in viewWillAppear:
[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[self.navigationBar setShadowImage:[UIImage new]];
[self.navigationBar setBarTintColor:[UIColor clearColor]];
self.navigationBar.translucent = YES;
and set it back in viewWillDisappear:
[self setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[self setShadowImage:nil];
[self setBarTintColor:THEME_COLOR];
self.translucent = NO;
I want to set the UINavigationBar translucent only in viewControllerB, so I put the code in viewControllerB. However, when I popToViewController B, I can see a black bar in the top right of the screen. Since the viewWillAppear is invocated. It seems can not be solved in my case.
I come out with some methods:
use different UINavigationBar.
use different UINavigationController. But UINavigationController can not push a new UINavigationController
Custom UIView like UINavigationBar.
I think above methos is more complicated。
Any ideas thanks!
That black color you see is the background color of main window. You can set background image or color to your main window from AppDelegate didFinishLaunchingWithOptions method (That's totally depends with your design of the view controller B) so that you won't see any difference.
Or else
Simply you can use viewDidAppear instead of using viewWillAppear, but that will have little flick though.

How to change the background color of navigation bar in a modal view?

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.

Change colour of Back Button, Navigation Title in UIPopoverController

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]];

UINavigationBar appearance refresh?

In my iPad app I have an application settings view. One of the options lets the user switch interface color scheme. The settings view is loaded by segue to a separate view controller than my "main" app's window.
When they pick a new color I switch the colorSchemeColor variable and do this:
// set the colors and refresh the view
[[UINavigationBar appearance] setBarTintColor:colorSchemeColor];
[[UIToolbar appearance] setBarTintColor:colorSchemeColor];
[[UITabBar appearance] setBarTintColor:colorSchemeColor];
However, none of the bars change color until I exit my settings view! (When the settings window disappears, the colors for the "main" app change correctly!)
So then I tried to put this code right after to refresh the settings view:
[self.view setNeedsDisplay];
[self.view setNeedsLayout];
which didn't help. So I added this as well:
[self.navigationController.view setNeedsDisplay];
[self.navigationController.view setNeedsLayout];
This didn't work either.
How can I get my settings view to "redraw" itself when the new color is picked so the change is instantly obvious?
Thanks so much!
The appearance proxy only affects the look of newly initialized views. Setting colors on the appearance proxy will have no effect on navigation bars that are already visible.
You'll need to manually update your current view; for example:
self.navigationController.navigationBar.barTintColor = [UINavigationBar appearance].barTintColor;
Objective-C:
self.navigationController.navigationBarHidden = YES;
self.navigationController.navigationBarHidden = NO;
Swift:
self.navigationController?.isNavigationBarHidden = true
self.navigationController?.isNavigationBarHidden = false
While I think Aaron Brager's answer is the ideal appraoch, my app needs about 15 different appearance settings and uses a split view controller, so I have to reapply all the setting to the global appearance and then apply them all to my two displayed views. That's a lot of redundant code.
Based on the idea that presenting and dismissing a modal view controller forces everything below it to redraw, I tried this and it worked perfectly:
UIViewController *redrawTrigger = [[UIViewController alloc] init];
redrawTrigger.modalPresentationStyle = UIModalPresentationFullScreen;
[mySplitViewController presentModalViewController:redrawTrigger animated:FALSE];
[mySplitViewController dismissModalViewControllerAnimated:FALSE];
[redrawTrigger release];

How do you set the background color of a UINavigationbar programatically?

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]];

Resources