【问题标题】:Custom tab bar background image - in iOS 4.x自定义标签栏背景图像 - 在 iOS 4.x 中
【发布时间】:2012-01-03 08:51:49
【问题描述】:

当我收到将标签栏的背景图像更改为自定义图像的请求时,我做了一个标签栏 iOS 项目。该项目是为 iOS 4.x 开发的,所以 iOS5 的 [tabBar setTabBarBackgroundImage:[UIImage imageNamed:@"custom.jpg"]] 不起作用。你能给我一些简单的解决方案吗(如果有可能,我不想改变整个项目)?

编辑: 只需三行代码即可解决所有问题:

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"customImage.png"]];
[self.tabBarController.tabBar insertSubview:imageView atIndex:0];
[imageView release];

【问题讨论】:

    标签: ios uitabbarcontroller uitabbar


    【解决方案1】:

    一个可能的解决方案是在UITabBar 后面放置一个带有背景图像的UIView。然后将标签栏的不透明度降低到 0.5,这样您就可以看到背景图像。

    UIView *bckgrndView = [[UIView alloc] initWithFrame:CGRectMake(tabbar.frame.coords.x, tabbar.frame.coords.y, tabbar.frame.size.width, tabbar.frame.size.height)];
    [bckgrndView setBackgroundImage:[UIImage imageNamed:@"custom.jpg"]];
    [tabbar.superView insertSubView:bckgrndView belowSubview:tabbar];
    tabbar.alpha = 0.5;
    [bckgrndView release];
    

    对不起,如果我的代码包含一些错误。我试着用心做这件事……但你会明白的。

    【讨论】:

    • 谢谢你,这是一个有用的想法:)
    【解决方案2】:

    我已经回答了类似的问题here。希望它会有所帮助。

    【讨论】:

      【解决方案3】:

      查看NGTabBarController,一个带有可自定义背景图像的开源标签栏替代品。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-09-01
        • 1970-01-01
        • 2018-02-22
        • 1970-01-01
        • 2021-09-30
        相关资源
        最近更新 更多