1

Is there a way so that I can increase the height of a single tab (UITabbarItem) keeping the rest of the tabs with same height in UITabBar.

Kunal Balani
  • 4,739
  • 4
  • 36
  • 73
  • 1
    Customize the `UITabBar` This may help you http://stackoverflow.com/questions/4640588/really-cool-way-to-create-custom-uitabbar-for-iphone-app – hp iOS Coder Sep 28 '12 at 05:07

4 Answers4

5

I am just taking a guess that you are trying to have an instagram (previous instagram) or keek like interface where one of the tabBarItems were much larger than the rest.

You have two options.

  1. Create a customTabBar with one of the items much larger. (I will not recommend this)

  2. Just keep the existing tabBarItems as they are. There is no need for a custom one. You will just have to create a UIButton with the required height and shape and add that on top of your tabBarItem.

Our work then comes down to creating a subclass of UITabBarController and add a custom UIButton on top of the UITabBar.

UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[button setBackgroundImage:highlightImage forState:UIControlStateHighlighted];

CGFloat heightDifference = buttonImage.size.height - self.tabBar.frame.size.height;
if (heightDifference < 0)
    button.center = self.tabBar.center;
else
{
    CGPoint center = self.tabBar.center;
    center.y = center.y - heightDifference/2.0;
    button.center = center;
}

[self.view addSubview:button];
Geek
  • 8,280
  • 17
  • 73
  • 137
Legolas
  • 12,145
  • 12
  • 79
  • 132
1

From my experience, you must extend the UITabBar class and when you initialize your UITabBarItems, set their heights accordingly. Also, create a background image for your UITabBar.

Alex Smith
  • 468
  • 5
  • 22
1

You can use customTabBar, here you can get sample of it, its nice classes and you can set tabBar item according to your size.

Link

Rajneesh071
  • 30,846
  • 15
  • 61
  • 74
1

In Swift 2.0, you can have a subclass of UITabBarController and add the UIButton using the following code:

let button: UIButton = UIButton(type: UIButtonType.Custom)
button.backgroundColor = UIColor.clearColor()
let buttonImage: UIImage = UIImage(named: "logo")!
let buttonImageHighlighted: UIImage = UIImage(named: "logoHighlighted")!
button.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, buttonImage.size.height);
button.setBackgroundImage(buttonImage, forState: UIControlState.Normal)
button.setBackgroundImage(buttonImageHighlighted, forState: UIControlState.Highlighted)

let heightDifference:CGFloat = buttonImage.size.height - self.tabBar.frame.size.height;
if (heightDifference < 0) {
    button.center = self.tabBar.center;
} else {
    var center: CGPoint = self.tabBar.center;
    center.y = center.y - heightDifference/2.0;
    button.center = center;
}

self.view.addSubview(button)
Navid Rezaei
  • 1,003
  • 11
  • 22