代码之家  ›  专栏  ›  技术社区  ›  JasonGenX

集中中央选项卡栏按钮

  •  1
  • JasonGenX  · 技术社区  · 14 年前

    这是怎么做到的?中央标签栏按钮的圆顶效果?这是一个简单的投影圆顶图像顶部的规则中心形状的选项卡按钮?或者还有别的吗?

    1 回复  |  直到 14 年前
        1
  •  3
  •   Midhun MP    14 年前

    您可以通过以下方式实现这一点:,

        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