Reputation: 2352
I am trying to add UITabBarController
programmatically. Everything is working fine but I am having two issues.
But it shows another green line at bottom like this:
Here is the code I am using for this:
[self.myTabBarController.tabBar setBackgroundImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"tabbar.png" ofType:nil]]];
Another issue is, I am setting tabbar item images using this code:
MyViewController *myController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
UINavigationController *myNavController = [[UINavigationController alloc] initWithRootViewController: myController];
[myNavController.tabBarItem initWithTitle:@"" image:[UIImage imageNamed:@"ads_inactive.png"] selectedImage:[UIImage imageNamed:@"ads_active.png"]];
Images are set but when i try to add title in MyViewController
's viewDidLoad
using this:
self.title = @"My Ads";
It shows same title on tabbar item too but I dont want any title there.
How I can fix this issue? Thanks
Upvotes: 0
Views: 1034
Reputation: 1003
The image size is less than the frame size of tab bar , so to cover to frame area background image show two times. You can change it in two ways 1.)Change the image size that will be not the best option 2.) set the content insets of tabBar like (0,0,0,0)
Upvotes: 3
Reputation: 159
Example:
UITabBar *tabBar = self.tabBarController.tabBar;
iterm0.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
UITabBarItem *iterm0 = [tabBar.items objectAtIndex:0];
[iterm0 setImage:[[UIImage imageNamed:@"tab1_normal"]
imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[iterm0 setSelectedImage:[[UIImage imageNamed:@"tab1_selected"]
[(UITabBarItem *)[self.tabBarController.tabBar.items objectAtIndex:0] setTitle:@""];
Upvotes: 0