集中中央标签栏按钮

时间:2012-08-14 19:36:05

标签: ios user-interface uitabbar

怎么做的?中央标签栏按钮的圆顶效果?它是一个简单的圆顶图像投影在常规中央形状的标签按钮的顶部?还是还有什么呢?

1 个答案:

答案 0 :(得分:3)

您可以通过

实现这一目标
    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];

请检查以下链接: http://idevrecipes.com/2010/12/16/raised-center-tab-bar-button/

您将获得https://github.com/boctor/idev-recipes/tree/master/RaisedCenterTabBar

的完整源代码