Change Split View Controller Navigation Bar Colour - ios

I have a split view controller and I want to change the navigation bar colour.
Using the below in app delegate I have changed the colour of the detail screen (right).
navigationController.navigationBar.barTintColor = UIColor.orangeColor()
But I can't seem to figure out how to change the bar of the navigation controller (left).
Can anyone help?
Thanks

The template provides you a MasterViewController (the left) and a DetailViewController (the right). It is the same code in both the MasterViewController and the DetailViewController, likely in viewDidLoad. You have it right, although there is an optional you are missing:
if let navContr = self.navigationController {
navContr.navigationBar.barTintColor = UIColor.orangeColor()
}

Related

How to overlap navigation bar by adding view in swift?

I want to make a custom side bar by adding a new view to the view controller, the side bar will be in the yellow color background. I want my side bar also to overlap the navigation bar/item (green background color) in my view controller. but the navigation bar/item seems can't be overlapped by my side bar view, it seems only overlap the main view.
I tried to find the answer in stackoverflow, I find this Overlap navigation bar on ios 6 with other view, but the answer is on the Objective-C, I can't read Objective-C :(
What should I do to overlap navigation bar/item ? here is the screenshot of my view controller
I embed the navigation controller like this
There are plenty of implementations of slide-over or drawer containers.
What you need to do to get above the navigation bar is CONTAIN the navigation controller inside another view controller.
The stack would look like this.
MasterViewController
UINavigationController
RootViewController
Menu
See this one here:
Swift version of MMDrawerController
You can do this by changing your UIViewController hierarchy. For this you'll need three view controllers. First will contain everything, let's call it MasterViewController; second—your main content with navigation bar; and third—drawer.
In MasterViewController instantiate child view controllers and add them to your view controller hierarchy in viewDidLoad().
final class MasterViewController: UIViewController {
override func viewDidLoad() {
let drawerViewController = DrawerViewController()
let mainViewController = MainContentViewController()
let navigationController = UINavigationController(rootViewController: mainViewController)
addChildViewController(drawerViewController)
addChildViewController(navigationController)
view.addSubview(navigationController.view)
view.addSubview(drawerViewController.view)
}
}
Now you have navigationController.view that you can place or animate anywhere within view.

swift: uicollectionview changes contentoffset of the cell during transition

I have a simple UICollectionView with a custom cell inside of a navigationController. For some reason when I push a viewController, the collectionView cell changes its layout during the transition.
Is it some common behavior of uicollectionview during viewController transition? Because, for example: labels don't have such problem
When back button was clicked
Green color from collectionView
Adding new view controller
navigationController?.pushViewController(controller, animated: true)
Setting Autolayout using EasyPeasy pod
collectionView.easy.layout([
Top(),
Right(),
Width(view.frame.width),
Bottom(10).to(button),
])
button.easy.layout([
Center(),
Height(60),
Width(300),
])
I think I've found your problem and it's in you AppDelegate. The property isTranslucent which is set to false to your navigation controller seems to cauese this rare problem. A translucent navigation bar will be on top of your viewcontroller's view, like above it. A non-translucent navigation bar pushes down your view controller's view or in other words rezising it so it fits beneath it.. But why the collectionview animates like it does is something I actually cant give a definite answer about. Maybe someone else could do that?..
To keep your navigation bar translucent you can set another property in your viewcontroller which is ´extendedLayoutIncluedsOpaqueBars´ to true.
So.. Do like this. In your AppDelegate:
window = UIWindow(frame: UIScreen.main.bounds)
window!.makeKeyAndVisible()
let controller = TestingNavigationController()
let navigation = UINavigationController(rootViewController: controller)
window!.rootViewController = navigation
let navigationBarAppereance = UINavigationBar.appearance()
navigationBarAppereance.isTranslucent = false
Then, in your view controllers viewDidLoad method add this line
extendedLayoutIncludesOpaqueBars = true
Hope this will solve your problem! :)
Apple Documentation about extendedLayoutIncludesOpaqueBars

Setting titleView of UINavigationItem makes titleView disappear

I've set the titleView of a UIViewController's navigationItem after init(). After pushing the VC to UINavigationController, titleView appears correctly at first time. But when I change (re-set) a titleView to an other view, it suddenly disappears.
But when I push another view controller and navigate back, it suddenly appears.
Do I have to perform any actions after re-setting the titleView?
If you are not using tab bar controller, then in viewDidLoad
setting the title as self.title is better.I have mentioned Tab bar Controller because if you have a view controller (in a NavigationController) in a UITabBarController, then if you set self.title it overrides the name of the tab as well as the top title.
I think you maybe code like this:
self.navigationItem.titleView = self.yourView;
If your yourView is a custom class , it maybe remove from superView when you switch your viewcontroller to next one;
So code like this maybe solve your problem:
[self.navigationItem.titleView addSubview:yourView];

How to embed in Navigation Controller to a tabbar controller

My initial view controller is a tab bar controller.I want to make the tab bar at top insted of bottom(which I have done using self.tabBarController?.tabBar.frame) . I want to make a navigation bar appear above the tab bar . Can anyone please hep me to do this
A UITabBar should always be at the bottom of the screen.
There is third party implementations of something that is similar to android tabs and might be what you are looking for.
Take a look at https://github.com/HighBay/PageMenu for example.
You can instantiate your view controller with the one of these codes
let VC1 = self.storyboard?.instantiateViewControllerWithIdentifier("storyboardID") as! DemoViewController
OR
let VC2 = YourViewController()
If your view controller is defined at the interface bulider , then go with the first else , go with the second.
Now to construct view array for tabBarController I put NavigationController as the element with rootViewController being the VCs I instantiated .
let tab1 = UINavigationController(rootViewController: VC1)
let tab2 = UINavigationController(rootViewController: VC2)
Describe the tabBarItem images like this
tab1.tabBarItem = UITabBarItem(title: nil, image: UIImage(named: "unselectedImage")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), selectedImage: UIImage(named: "selectedImage")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal))
Finally describe the tabBar array
self.viewControllers = [tab1,tab2] //This will create tabBar with 2 tabs
Your navigation controller will appear at the top with this. You can customize your Navigation Bar. For that see this.
Also don't forget to make your tabBarController the rootViewController in the AppDelegate. Otherwise you will go against Apple guidelines.
Hope this helps. :)
My suggestion is that make viewcontroller and use the UISegmentController to perform the Tab Bar Actions below the Navigation Bar..
thank you

How to set the navigation bar title from view controllers inside tabs?

I have a tab bar controller embedded in a navigation controller.
I want to set the title in the navigation from the view controllers inside the tabs.
If I use:
self.title = "ABC";
or
self.tabBarItem.title = "ABC";
the title of the tab at the bottom is set to "ABC", but not the title in the navigation bar at the top.
However, I only want to set the title in the navigation bar, not the tabs at the bottom.
How can I do that?
You can set it using self.navigationItem.title.
self.navigationItem.title=#"ABC";
You have to pass the navigationItem up the chain.
The UINavigationController shows the navigationItem belonging to its topViewController which is UITabBarController.
The UITabBarController shows the navigationItem titles in its tabs. So what you need to do is make sure that the tabBarController's navigationItem is it's selectedViewController's navigationItem
So to recap:
UINavigationController title = topViewController.navigationItem.title
UITabBarController tabTitle = selectedViewController.navigationItem.title
UIViewController title = navigationItem.title
You are probably using the wrong element, try with the following example :
self.tabBarController.title = #"YOUR_TITLE";

Resources