Dual TabBars in StoryBoard IOS - ios

I've seen that there isn't any possibility of adding a custom tab bar in TabBarController in StoryBoard of IOS. However a single tabBar can contains multiple buttons. But I want to design two tab bars (first one on top and second one on bottom of storyboard) and the content I want to see in the middle of both tabBars. How can I design my custom tabBars using storyboard?
I'm currently designed in xib but I want to get rid of the xib and have to design an autolayout tab bars on storyboard and to avoid remove sub views again and again when each button is called.
Is it possible to design dual tabbars in storyboard?

You can't have 2 tab bar controllers at the same time. The tab bar controller won't allow it, and Apple would very likely reject your app if you created that look yourself. It sounds like a really bad user interface, frankly.
That said, if you want to create an UI with a normal tab bar on the bottom of the window and another thing that looks and acts like a tab bar at the top, you could create a custom parent view controller class and implement your "top tab bar" look yourself, then use that custom view controller as one of the tabs in your tab bar controller. However, I'd bet money that Apple would reject such a thing as a violation of the HIG (Human Interface Guidelines).

Related

IOS Custom View or Navigation Bar Controller

I am new to IOS Swift development. I have a navigation bar design which includes, increasing the height (thus increased text size with custom colors), custom UIButton for closing (instead of the usual back button)
and title at the left side (instead of center)
Basically a lot of customization to do. My question is, is it okay to do a custom UIView to act as a navigation bar or should I push through with a NavigationController and just customize it via code?
Thank you.
First of all the navigation bar offer the push navigation through different view controllers in a smarter way, it stacking all the view controllers pushed and it offers some useful features; for example pushing another view controller from storyboard you don't have the need to set the back button and you can come back to the main controller in a simple way.
You can set a custom image for left/right button, set custom fonts and also change the height without big problems; I suggest to keep the navigation bar and evaluate, you should discover in a short time if a nav bar is enough for your needs.

Xcode 6 - Swift - Custom Tabbar with Navigation

I'm trying to create a tabbed application with navigation elements inside the tab bar, as seen in the picture below (the red bar) using Swift/XCode 6.2. Basically those three icons in the middle will direct the user to different view controllers. The other two icons would be context-based. For example, on a table view page you would see the menu icon and add new icon as seen in the image. However, clicking on a row would change the menu icon to a back icon, and the add icon to something else.
That's the general idea, but I'm having a very hard time implementing something even close to this. The first issue is that whenever I embed a view in a Tab Bar Controller, I can't move the tab bar to the top. However, when I create a custom UITabView in a View Controller, Control + Click and dragging a Tab Bar Item to another view doesn't create a segue. I haven't even begun to tackle having the navigation elements inside the bar.
I guess what I'm asking is just for a little guidance on what route to take to tackle this. I'm assuming I can't use a Tab Bar Controller or Navigation Controller because it doesn't seem like I can customize them all that much. So custom Tab Bar and Navigation Bars, and then implemnt the segues and button changes programmatically?
Thanks.
I will try to guide you from an architectural perspective (so you won't find much code below).
Using a UITabBarController
In order to achieve what you are suggesting, you are right you cannot use a UITabBarController straight away, among several reasons, the most immediate one is that they are meant to be always at the bottom and you want it in top (check Apple's docs). The good news is that probably you don't need it!
Note: If you still want to go with a UITabBarController for whatever reason, please see #Matt's answer.
Using a UINavigationController
You can use a UINavigationController to solve this task, since the UINavigationBar of a UINavigationController can be customized. There are multiple ways on how you can organize your view's hierarchy to achieve what you propose, but let me elaborate one option:
To customize a UINavigationBar's to add buttons, you just need to set its navigationItem's title view:
// Assuming viewWithTopButtons is a view containing the 3 top buttons
self.navigationItem.titleView = viewWithTopButtons
To add the burger menu functionality on a UINavigationController you can find several posts on how to do it and infinite frameworks you can use. Check this other SO Question for a more detailed answer (e.g. MMDrawerController, ECSlidingViewController to mention a couple).
About organizing your view hierarchy, it really depends on if when the user taps one of the main top buttons, it will always go to the first view controller in the new section or if you want to bring him back to the last view in the section where he was.
3.1 Switching sections displays the first view of the new section
Your app's UIWindow will have a single UINavigationController on top of the hierarchy. Then each of the 3 top buttons, when tapped, will change the root view controller of the UINavigationController.
Then, when the user changes section, the current navigation hierarchy is discarded by setting the new section view controller as the UINavigationController root view controller.
self.navigationController = [sectionFirstViewController]
3.2 Switching sections displays the last displayed view in the new section
This will require a slightly modified version of the above, where your each of your sections will have its own UINavigationController, so you can always keep a navigation hierarchy per section.
Then, when the user taps one of the top buttons to switch section, instead of changing as previously described, you will change the UIWindowroot view controller to the new section's UINavigationController.
window.rootViewController = sectionNavigationController
Using a custom implementation
Of course, the last and also very valid option would be that you implement yourself your own component to achieve your requirements. This is probably the option requiring the biggest effort in exchange of the highest customizability.
Choosing this option is definitely not recommend to less experienced developers.
I'd like to take a stab at this--I think it is possible to use a tab bar controller here.
Your topmost-level view controller will be a UITabBarController with a hidden UITabBar.
Each tab is contained in a UINavigationController.
All view controllers in the navigation controller will be a subclass of a view controller (say, SwitchableViewController).
In SwitchableViewController's viewDidLoad, you set the navigation item's title view (i.e. whatever's at the center; self.navigationItem.titleView) to be the view that holds the three center buttons. Could be a UISegmentedControl, or a custom view.
Whenever you tap on any of the buttons, you change the topmost UITabBarController's selected index to the view controller you want to show.
Issues you may encounter:
Table views inside tabs will have a scrollIndicatorOffset at the bottom even if the tab bar is hidden.
Solution: Play around with the automaticallyAdjustsScrollViewInsets of the tab bar controller, or the inner view controller. https://stackoverflow.com/a/29264073/855680
Your title view will be animated every time you push a new view controller in the navigation stack.
Solution: Take a look at creating a custom transition animation for the UINavigationController.

Single navigation bar in iOS tabbed app

I'm doing iPhone tabbed application, but I need to use navigation bar also (just for app title and single icon for Settings in the corner) like twitter did: link. I have 4 tabs in my app too. I was wondering is there any chance to create only one navigation bar, so when I want to change it, I will change it only in one place?
I was looking at this tutorial, but there are two "Navigation Bar" objects. And I would like to have single object that will appear in every tab.
Right now I created tabbed app and manually added navigation bar item into first tab. Then I copied it into others. It works ofc, but I'm not sure about that solution:/
Your use of separate navigation controllers for each tab isn't a bad solution.
Setting up the navigation bar and its items in only one place is also a good idea. To achieve this, you could always have your view controllers derive from a custom view controller that overrides navigationItem.

Different types of Navigation controller/view/bars

Can somebody explain the difference pros/cons of following things related to navigation in iOS.
Just in case, if it's relevant. I use XCode 4.5 and xibs.
1) If I choose a view in Interface Builder and choose "Attributes inspector", there is an item called "Top Bar" and I can choose "Navigation Bar" in there.
I did some experimenting. It's displayed in Interface Builder, but looks like it doesn't influence anything in runtime. Am I missing something
2) In Interface Builder, I can drag and drop "Navigation Controller" from Objects list and add some View in it.
3) In Interface Builder, I can drag and drop "Navigation Bar" and put it on some view
It's not clear for me what is the difference between item #2 and #3
1) The things that you can add in the Simulated Metrics section are just to help you lay things out in IB, it doesn't actually add them.
2) & 3) A navigation controller allows you to do push and pop transitions between view controllers that are embedded in it. It takes care of changing the titles in the navigation bar and the text in the back button. You can't do a push segue or use pushViewController:animated: in code if your controllers aren't embedded in a navigation controller. A navigation bar is just a UI element that normally goes at the top of the screen and can contain navigation items. By itself, it doesn't do anything. You have to write the code that takes care of titles and button text. Adding a navigation bar to a view doesn't make it so you can do a push, only embedding it in the UINavigationController allows you to do that.
Let me answer all the question together by showing a simple method. Just use StoryBoards because they are really simple and shows more clearly what is happening.
All you need to do is to select the view controller (let us say your primary view controller) and go to the menu then Editor > Embed In > Navigation Controller. It will all make sense then.

"Slide" segue between UITabBar views

My iOS 5 app uses storyboarding with a UITabBarController. There are three "tabs" each displaying a view controller which has been linked using a relationship back to the UITabBarController. At the moment each view controller appears when you tap the relevant tab, as expected. However, for a more gracious transition I would like to slide the view controllers on and off screen.
By way of example, if I am currently on Tab 0 and then select Tab 1 the view controller on screen (for Tab 0) should slide off to the left-hand side of the screen, and the new view controller (for Tab 1) should slide on from the right-hand side of the screen.
I have been able to achieve this behaviour using a custom UIView as the tab bar but would like to know whether this is possible with a custom segue in storyboarding, as that would certainly save a lot of coding (and also would keep things a fair bit neater in the project)?
Thanks in advance for any assistance.
I am trying to do the same thing.
Unfortunately I think the relationship segue does not allow any customization as it just connect tab bar and the tab bar items together, and not a transition.
My guess is we have to do the transition ourselves when the view appeared.

Resources