Search code examples
iosuser-interfaceuitabbar

centralizing the central tab bar button


How is that done? that dome effect for a central tab bar button? is it a simple projection of the dome image on top of the regularly central shaped tab button? or is there anything more to it?


Solution

  • You can achieve this by,

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

    Please check these links: http://idevrecipes.com/2010/12/16/raised-center-tab-bar-button/

    You will get the full source code at https://github.com/boctor/idev-recipes/tree/master/RaisedCenterTabBar