Search code examples
iosuibuttonuitabbarcontrollercustom-controlsuitabbar

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!!!!

enter image description here


Solution

  • I recommend you taking a look at the following article. It explains how to customise a tab bar raising the main button.

    Code:

    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];
    

    Guide: https://github.com/boctor/idev-recipes/tree/master/RaisedCenterTabBar