Eesha
Eesha

Reputation: 171

How to Add TabBar Images to each tab? on XCode 8.1

I am using Xcode 8.1, on that when I uses TabBarViewController, it doesn't shows separate buttons for each tab, I want to add each Tab's specific image and title.

Following is the screenShot. My Problem is very Simple, I only want to Add Icons and titles to each Tab.

I am beginner. Any Idea will be Appreciated.

enter image description here

Upvotes: 1

Views: 1242

Answers (2)

Y. J. Leong
Y. J. Leong

Reputation: 39

I'm using XCode 8.2.1, but the procedure should be similar to XCode 8.1

Steps to add image into tab 1. In your storyboard, drag a TabBarController from the palette, it comes with 2 default ViewController

  1. Highlight one of the Default ViewController
  2. Select item1 as shown in this image Item1 Sample
  3. Switch to Attributes Inspector Tab as shown in this image Attributes Inspector Sample
  4. Then change the value of Title and Image to what you want.
  5. You're done.

In case You want to know how to manually link those ViewController together.

  1. Drag one TabBarController from the palette.
  2. Remove Both Default ViewController come along with TabBarController.
  3. Drag one ViewController from the palette.
  4. Control+Drag from TabBarController to ViewController.
  5. Select 'view controller' under Relationship Segue.
  6. Then Follow the steps in upper section to add your image and title of your tab bar item

Upvotes: 1

Bohm
Bohm

Reputation: 1004

If I understand correctly and you are trying to customize the button icons in the tapbar, then you can do it programmatically using this code for each tapbar button index:

UITabBarController *myTabBar = [[UITabBarController alloc] init];

UITabBarItem *tabButton1 = [myTabBar.items objectAtIndex:0];
[tabButton1 setSelectedImage:[UIImage imageNamed:@"selected_image"]];
tabButton1.selectedImage = [[UIImage imageNamed:@"selected_image"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabButton1.image = [[UIImage imageNamed:@"unselected_image"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabButton1.title = @"Button 1 title";

NSArray *arrayViewControllers = [NSArray viewController1, viewController2, viewController3, nil];
[myTabBar setViewControllers:arrayViewControllers animated:NO];

Alternatively, you can set the image in the storyboard but keep in mind that the image alpha channel will be used to generate the select/unselect color tonality. That sometime lead to strange effects.

Upvotes: 0

Related Questions