Questions tagged [uitabbarcontroller]

The UITabBarController class implements a specialized view controller that manages a radio-style selection interface. This tab bar interface displays tabs at the bottom of the window for selecting between the different modes and for displaying the views for that mode. This class is generally used as-is but may be subclassed in iOS 6 and later.

The UITabBarController class implements a specialized view controller that manages a radio-style selection interface. This tab bar interface displays tabs at the bottom of the window for selecting between the different modes and for displaying the views for that mode. This class is generally used as-is but may be subclassed in iOS 6 and later.

Each tab of a tab bar controller interface is associated with a custom view controller. When the user selects a specific tab, the tab bar controller displays the root view of the corresponding view controller, replacing any previous views. (User taps always display the root view of the tab, regardless of which tab was previously selected. This is true even if the tab was already selected.) Because selecting a tab replaces the contents of the interface, the type of interface managed in each tab need not be similar in any way. In fact, tab bar interfaces are commonly used either to present different types of information or to present the same information using a completely different style of interface. Figure 1 shows the tab bar interface presented by the Clock application, each tab of which presents a type of time based information.

enter image description here

You should never access the tab bar view of a tab bar controller directly. To configure the tabs of a tab bar controller, you assign the view controllers that provide the root view for each tab to the viewControllers property. The order in which you specify the view controllers determines the order in which they appear in the tab bar. When setting this property, you should also assign a value to the selectedViewController property to indicate which view controller is selected initially. (You can also select view controllers by array index using the selectedIndex property.) When you embed the tab bar controller’s view (obtained using the inherited view property) in your application window, the tab bar controller automatically selects that view controller and displays its contents, resizing them as needed to fit the tab bar interface.

Tab bar items are configured through their corresponding view controller. To associate a tab bar item with a view controller, create a new instance of the UITabBarItem class, configure it appropriately for the view controller, and assign it to the view controller’s tabBarItem property. If you do not provide a custom tab bar item for your view controller, the view controller creates a default item containing no image and the text from the view controller’s title property.

As the user interacts with a tab bar interface, the tab bar controller object sends notifications about the interactions to its delegate. The delegate can be any object you specify but must conform to the UITabBarControllerDelegate protocol. You can use the delegate to prevent specific tab bar items from being selected and to perform additional tasks when tabs are selected. You can also use the delegate to monitor changes to the tab bar that are made by the More navigation controller, which is described in more detail in The More Navigation Controller.

For more information about using tab bar controllers to build your user interface, see View Controller Programming Guide for iOS.

The Views of a Tab Bar Controller

Because the UITabBarController class inherits from the UIViewController class, tab bar controllers have their own view that is accessible through the view property. The view for a tab bar controller is just a container for a tab bar view and the view containing your custom content. The tab bar view provides the selection controls for the user and consists of one or more tab bar items. Figure 2 shows how these views are assembled to present the overall tab bar interface. Although the items in the tab bar and toolbar views can change, the views that manage them do not. Only the custom content view changes to reflect the view controller for the currently selected tab.

enter image description here

The More Navigation Controller

The tab bar has limited space for displaying your custom items. If you add six or more custom view controllers to a tab bar controller, the tab bar controller displays only the first four items plus the standard More item on the tab bar. Tapping the More item brings up a standard interface for selecting the remaining items.

The interface for the standard More item includes an Edit button that allows the user to reconfigure the tab bar. By default, the user is allowed to rearrange all items on the tab bar. If you do not want the user to modify some items, though, you can remove the appropriate view controllers from the array in the customizableViewControllers property.

State Preservation

In iOS 6 and later, if you assign a value to this view controller’s restorationIdentifier property, it preserves a reference to the view controller in the selected tab. At restore time, it uses the reference to select the tab with the same view controller.

When preserving a tab bar controller, assign unique restoration identifiers to the child view controllers you want to preserve. Omitting a restoration identifier from a child view controller causes that tab to return to its default configuration. Although the tab bar controller saves its tabs in the same order that they are listed in the viewControllers property, the save order is actually irrelevant. Your code is responsible for providing the new tab bar controller during the next launch cycle, so your code can adjust the order of the tabs as needed. The state preservation system restores the contents of each tab based on the assigned restoration identifier, not based on the position of the tab.

For more information about how state preservation and restoration works, see App Programming Guide for iOS.

6522 questions
27
votes
1 answer

Swift setting Badge Value for UITabBarItem

I'm attempting to add a badge alert label like the one in the screenshot attached. I've tried to search for titles, labels uitabbar items but I'm stuck. Any suggestion is appreciated.
Gino
  • 951
  • 1
  • 12
  • 24
27
votes
6 answers

How do I pass data from a tab bar controller to one of its tabs?

I have a UITabBarController set up in storyboard. I want to pass a dictionary of data from the tab bar controller for use in the appropriate child tab, which is a standard UIViewController. This seems like a long questions to answer, but I really…
26
votes
8 answers

Load All TabBar Views

I have a tabbar controller as the root view controller. I would like to pre-load the views of tab [1,2,3] (tab 0 loads as the first tab automatically). I essentially would like the code in viewdidload to run before the user taps on the tab. Thanks
Laurent May
  • 265
  • 1
  • 3
  • 5
26
votes
11 answers

How can I change the top border of my UITabBar?

I'd like the UITabBar to have a top border of width 5.0. The border should be yellow color. I don't want any left/bottom/right borders. The Tab Bar border should be flat (no shadows or anything like that). How can I remove shadow (image) line?
TIMEX
  • 259,804
  • 351
  • 777
  • 1,080
26
votes
6 answers

Swift: how to show a tab bar controller after a login view

I have seen many posts similar to this here but they are all about Objective-C while I am developing my app in Swift. As you can see from the image I have a login screen view and I correctly implemented the login mechanism. Now I would like that…
SagittariusA
  • 5,289
  • 15
  • 73
  • 127
26
votes
8 answers

Detect UITabBar Selected Index/ Item Changes that is set Programmatically

I would like to know how do we detect when the selected TabBar Item or Index is changed when the changes is done programmatically? self.tabBarController.selectedIndex = 1; This two delegate function only detect changes when the tabBar Item was…
JayVDiyk
  • 4,277
  • 22
  • 70
  • 135
26
votes
1 answer

How can I programmatically set selected tab of UITabBarController while also triggering shouldSelectViewController in UITabBarControllerDelegate

I'm trying to animate the transitions between tabs in my UITabBarController, which is working fine when I push on the tab buttons. However, when I switch tabs programmatically by calling [self.tabBarController setSelectedIndex:2]; in a swipe…
herrtim
  • 2,697
  • 1
  • 26
  • 36
25
votes
16 answers

How to disable the edit button that appears in the more section of a UITabBarController?

In my application (based on the Tab bar application XCode template) I use a UITabBarController to display a list of different sections of the application that the user can access. By default, the UITabBarController displays a 'More' button in the…
Panagiotis Korros
  • 10,840
  • 12
  • 41
  • 43
25
votes
2 answers

Objective C: How to switch from one Tab bar to another via program

I have 5 different tabs in my tabbar controller. My intention is to be able to switch from one tab bar via code. For example I am currently in the 5th tab of the app and when I click on the 'done' button, the app should switch my view to the…
Zhen
  • 12,361
  • 38
  • 122
  • 199
24
votes
10 answers

How to Hide Tab Bar Controller?

How to Hide Tab Bar Controller ? I want to hide the Tab Bar controller with double tap on UIImageView.
Gaurav Patel
  • 957
  • 1
  • 6
  • 16
24
votes
3 answers

last Button of actionsheet does not get clicked

I have used an actionsheet in my project and when it appears it show all buttons but last (4th) button does not responds to my click(only it's half part responds).. I know the reason it is because i have used a TabBarController and the present class…
Ranjeet Sajwan
  • 1,925
  • 2
  • 28
  • 60
24
votes
4 answers

Swift: Change the image tint color of tab bar?

I have created the tabBarController programmatically and I want to change color of tint color of images (not the bar) that tab contains. Can anyone tell me how to do that in Swift?
Rahul Sonvane
  • 3,737
  • 7
  • 18
  • 21
24
votes
4 answers

iOS TabbarViewController hide the tab bar

I have a viewcontroller that it implement UITabbarViewController, and I want to hide the tab bar and override it by myself, self.tabBar.hidden = YES; the tab bar disappeared BUT there is a blank area(the blue one) at the bottom of the view. I dont…
jxdwinter
  • 2,339
  • 6
  • 36
  • 56
23
votes
6 answers

Tab bar not showing icons?

I read a bunch of related questions, I tried what they said, nothing works really. Not sure why. So, I have 3 different UIStoryboards. First one is the Auth Storyboard that handles Login/Register and there's a storyboard reference to the second…
Dani
  • 3,427
  • 3
  • 28
  • 54
23
votes
12 answers

iOS 7.1 issue - Tabbar icon image is automatically resize when touch and drag on that tab button

I have this code [tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"tab_pressed_home_icon"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_home_icon"]]; tabBarItem1.imageInsets = UIEdgeInsetsMake(8, 0, -2, 0); which set an icon on…
SaintTail
  • 6,160
  • 4
  • 31
  • 51