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
69
votes
14 answers

Unselected UITabBar color?

I have an UITabBar with 5 items. I want to change the unselected color of all items. The items aren't declared in the UIViewController classes (i built them and linked the views in the Storyboard). Is there an code like this : [[UITabBar appearance]…
user1530090
  • 705
  • 1
  • 5
  • 6
66
votes
6 answers

Changing the background color of Tab Bar

I am trying to get desired color rendered in the background of Tab Bar however I am facing problems. These are the things that I tried :- Changing the background color of tab bar object from storyboard. The color rendered is always lighter than…
MrDank
  • 2,020
  • 2
  • 17
  • 39
61
votes
20 answers

How to change inactive icon/text color on tab bar?

How can I change inactive icon/text color on iOS 7 tab bar? The one in gray color.
Pablo
  • 28,133
  • 34
  • 125
  • 215
60
votes
8 answers

How to hide/show tab bar of a view with a navigation bar in iOS?

I have views with a navigation bar and a tab bar. What I would like to happen is to hide the tab bar on a certain view and show the tab bar again when the user changes views. I saw a snippet of code for hiding the tab…
dork
  • 4,396
  • 2
  • 28
  • 56
60
votes
8 answers

How to get the height of the tabbar programmatically?

I've found out that the height of a UITabBar is 49px (or 50px, depending on the source). Because I don't like to use too much hard-coded values in my code I was wondering if it is possible to retrieve the height of the tabbar programmatically. Kind…
Niels R.
  • 7,260
  • 5
  • 32
  • 44
60
votes
7 answers

How to set the tab bar badge with swift?

How to set the tab bar badge with swift ? for example when I get new message showing number 1 on the message icon ! Do I have to use the UITabBarItem.swift and write the code in it ! I'm not really sure how I can do it Thank you !
Faris
  • 1,206
  • 1
  • 12
  • 18
60
votes
8 answers

How do we create a bigger center UITabBar Item

I am wondering how do we create a bigger center UITabBar like the shot below? Its really beautiful!!!!
JayVDiyk
  • 4,277
  • 22
  • 70
  • 135
58
votes
4 answers

Switch tab bar programmatically in Swift

I have a tab bar application and i have a button on my first view which i want to when pressed switch to my second tab programmatically in the tab bar. I can't quite seem to figure it out how to get the index etc to switch to it i've tried stuff…
Azabella
  • 837
  • 2
  • 10
  • 18
58
votes
12 answers

Setting the default tab when using storyboards

Can anyone please tell me how to set the default tab when using storyboards in iOS. I can't seem to figure out how to accomplish this. Thank you
user1145581
  • 1,017
  • 4
  • 13
  • 18
55
votes
3 answers

How to implement tab bar controller with navigation controller in right way

I am using Storyboard and Xcode 6. I have next controllers and scenes in my Storyboard: UINavigationController that has HomeViewController as a root. HomeViewController has a button that Show (e.g. Push) UITabBarController. UITabBarController has 4…
52
votes
4 answers

View Controllers: How to switch between views programmatically?

In short: I want to have two fullscreen views, where I can switch between view A and view B. I know I could just use an Tab Bar Controller, but I dont want to. I want to see how this is done by hand, for learning what's going on under the hood. I…
Thanks
  • 40,109
  • 71
  • 208
  • 322
49
votes
3 answers

How add tabs programmatically in UITabBarController with swift?

How to create programmatically tabs from any class extended by UIViewController: class DashboardTabBarController: UITabBarController { override func viewDidLoad() { //here } ... }
gellezzz
  • 1,165
  • 2
  • 12
  • 21
43
votes
10 answers

Auto Layout and "Hide bottom bar when pushed"

My app's (simplified) structure is this: UITabBarController with one UINavigationController holding a UITableViewController as root view controller. when tapping one of the table view controller cells, I push a regular UIViewController (lets call…
Eyal
  • 10,777
  • 18
  • 78
  • 130
43
votes
12 answers

iOS 7 tabBar-line, how to remove it?

Apple has added a tiny line over the tabBar in iOS 7 which is supposed to work as a shadow or fade between the tabBar and the UI Since I am using a custom-made tabBar the line is quite irritating. How do you remove it? Please tell me it is…
43
votes
15 answers

iOS UITabBar : Remove top shadow gradient line

I implemented a custom UITabBar and I still have this gradient/shadow on top of it. I added [self.tabBar setBackgroundImage:[UIImage imageNamed:@"navBarBottom.png"]]; which is just changing the background but keeping the shadow gradient. What am I…
httpete
  • 5,875
  • 4
  • 32
  • 41