I made an apps with only using XIB (without storyboard). so to navigate I'm using this code to push some of the views:
let vc = SecondViewController()
self.navigationController?.pushViewController(vc, animated: true)
I already make the first vc as rootvc, so it automatically created navigation bar for me.
the problem is the navigation bar generated not at top of the screen and leaving some white space gap. So here is the image when I'm using large title
and here is the normal one
I have tried to run it without safe area layout as well.
what happened is the navbar stayed there but the view goes up (through behind navbar).
navigationController.isNavigationBarHidden = true
Try adding this line to your code for hide default navigation bar.
I've experienced this kind of problem, too.
There are many ways to remove white space.
I want to help you this way.
Add UIView above navigation Bar.
and then, Fix UIView Top constraint.
and change UIView Color.
this is result.
Again, there are many ways...
Use this in your view controller's class:
navigationController?.setNavigationBarHidden(true, animated: animated)
you can change your status bar colour by using. i don’t remember the code but from here you can also can also change your colour in two Default styles
//and use this to hide and show your navigation bar
navigationController.isNavigationBarHidden = true
Related
I have an issue and I'm not sure how to approach this. I have a dynamic custom UITabBarController and I'm setting its viewControllers like this
setViewControllers(viewControllers, animated: false)
Is working fine but I also want to hide the tabBar under certain scenarios. For this I'm just doing this:
tabBar.isHidden = true
So far so easy. But I realised that the current selectedViewController has some buttons attached to the bottom using some constraints and they're not being updated when the tab bar is hidden or displayed again. If I change to another tab and then go back, the view is refreshed and everything is fine, so I tried using selectedViewController?.view.layoutIfNeeded() once the tab bar visibility changes, but didn't work.
Anyone can give an idea of what's happening? Thanks.
I'm currently updating an old Xcode project I started working on a long time ago. I updated the deployment target to iOS 10.0 so I was forced to replace the ABAddressBook framework with Contacts framework. I used to present the ABPeoplePickerNavigationController inside a Container View, which was a subview of the root view controller of a UINavigationController. That way I was able to present the People Picker UI inside a navigation controller, which was inside a tab bar controller (which meant that the navigation bar at the top and the tab bar at the bottom were still displayed around the people picker UI). I used to do it with this code (called in viewWillAppear of navigation controller's root view controller:
let peoplePickerNavController:ABPeoplePickerNavigationController = ABPeoplePickerNavigationController()
self.addChildViewController(peoplePickerNavController)
peoplePickerNavController.didMove(toParentViewController: self)
peoplePickerNavController.navigationBar.removeFromSuperview()
peoplePickerNavController.view.frame = self.peoplePickerContainerView.bounds
peoplePickerNavController.view.translatesAutoresizingMaskIntoConstraints = true
peoplePickerNavController.peoplePickerDelegate = self
self.peoplePickerContainerView.addSubview(peoplePickerNavController.view)
With this code, it would display the address book perfectly with the navigation bar of the navigation controller still at the top and the tab bar of the tab bar controller still at the bottom. I'm trying to do the same thing now with CNContactPickerViewController, but I'm having a little trouble with this one. When I do the same thing I did with the navigation controller, it doesn't give me any errors but the view controller is not being displayed. Even though I'm adding the view of the view controller to my container view, it's just showing an empty white view. This is the code I'm using now:
let contactPickerViewController:CNContactPickerViewController = CNContactPickerViewController()
self.addChildViewController(contactPickerViewController)
contactPickerViewController.didMove(toParentViewController: self)
contactPickerViewController.view.frame = self.contactPickerContainerView.bounds
contactPickerViewController.view.translatesAutoresizingMaskIntoConstraints = true
contactPickerViewController.delegate = self
self.contactPickerContainerView.addSubview(contactPickerViewController.view)
The only significant difference between those two codes is that I'm not removing the navigation bar from the view controller (because it doesn't have one). Other than that, I left everything pretty much the same. I'm guessing I need to change a few other things in order to make this work, since there is a difference between adding a navigation controller to the Container View and adding a View Controller. Can anyone help me out and give me some tips on how to achieve this? Thank you!
Use this code to display contactPickerViewController inside tabBar
let contactPickerViewController:CNContactPickerViewController = CNContactPickerViewController()
contactPickerViewController.modalPresentationStyle = .overCurrentContext
self.presentViewController(contactPicker, animated: false, completion: nil)
I have a label I placed at the top of the screen as a header. I want to keep that viewable and still present when I add a navigation controller by embedding it.
I am mostly using the storyboard to help me create the UI.
This is what the app looks like without a navigation controller:
However, if I add a navigation controller I get the following:
Certainly I would like to maintain a navigation controller so that I won't have to incorporate my own buttons which control navigation. As I understand it, at this time the Marketplace logo is hidden behind the nav controller.
You can use two methods here :
1) Keep using your label, and hide the navigation bar , your app will still have navigation, just the top navigation bar will be hidden.
For this, use this code:
viewDidLoad()
{
self.navigationController?.navigationBar.isHidden = true
}
2) The second method is a alternate to what you want, but its good if you Need text At top only. In this we will not use label, instead we'll set title of the navigation bar itself.
viewDidLoad()
{
self.navigationItem.title = "MarketPlace"
}
Maybe there are more methods, but these two i've used.
You can try navigationItem.titleView = yourView
In Objective-C it would be something like this:
navigationController.navigationBar.hidden = YES;
When I'm tabbing between pages attached to a navigation controller, sometimes there is a black mark under the navigation bar..
any ideas how to remove this?
they're just blank pages.
let vc = self.storyboard!.instantiateViewController(withIdentifier: page)
self.show(vc, sender: self)
i have tried setting background to white in navigation controller class like some threads recommend which didn't do anything.
The "smudge" happens when you transition between a view controller whose edgesForExtendedLayout include .top and one that does not. To avoid it, make sure all your view controllers have the same edgesForExtendedLayout and the same extendedLayoutIncludesOpaqueBars settings.
for me, It happens when I use ToolBar from libraries. fix by using ToolBar from the navigation controller itself by toggle "Shows Toolbar" in Navigation Controller's Attribute Inspector
I had this issue with my app as well, except I had a black smudge under the Navigation Bar and a Toolbar. I eventually discovered that the problem was because of the isTranslucent property of the UIToolbar I had in multiple scenes.
Once I set this property to false, the black smudge under both the Navigation Bar and the Toolbar went away (why disabling translucency on the Toolbar fixes the Navigation Bar as well, I don't know). I had tried disabling isTranslucent on the UINavigationBar, but that only fixed the smudge on top. Luckily, in my case, nothing will ever be under the Toolbar, so disabling translucency is not a problem. If translucency under the Toolbar is required, this solution may not work for you.
When trying to add a navigation bar for searching on the left button and eventually a setting button on the right bar button, the bar isn't showing up in the simulator. Screenshot
Should I be using a regular toolbar like the temporary one I have on the bottom? I'd prefer the search button for loading new addresses, and settings for the obvious, but then I want buttons that serve as navigations for moving from tab to tab. Should I simply implement a search bar above the map view and a settings button on the right? I'm new to xcode and it's kicking my ass.
EDIT: After changing the hidden to "self.navigationController?.setToolbarHidden(false, animated: true)" the toolbar appeared but at the bottom below the current toolbar with zoom and type buttons. So it looks as if it thinks it's a toolbar and only wants to put it at the bottom?
self.navigationController.navigationBar.hidden = false;
Use above code to show navigation bar.
I Believe you might be aligning the top of the Map View to the top of the top layout guide, if this is the case your toobar might be hidden behind the map view. I would change that constraint that constraint in the map view and use "vertical spacing" to the tool bar in the top and give it a value of 0.
Don't add navigation bar manually If you are adding. You will get Your navigation bar with your navigation controller. In your viewWillAppear()
put the line of code self.navigationController?.setNavigationBarHidden(false, animated: true).
Swift 4 solution
Add this code to your ViewController:
override func viewWillAppear(_ animated: Bool) {
self.navigationController?.navigationBar.isHidden = false
}