【问题标题】:How to set image background to UITabBarController iOS 5如何将图像背景设置为 UITabBarController iOS 5
【发布时间】:2011-12-08 10:44:21
【问题描述】:

您好,有人可以帮我编写这段代码吗?我有带有自定义标签栏图像的应用程序,现在在 iOS5 中图像消失了。我知道他们已经对标签栏的实现进行了更改,我不知道如何解决这个问题。

- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window makeKeyAndVisible];
CGRect frame = CGRectMake(0, 0, 400, 148);
UIView *viewa = [[UIView alloc] initWithFrame:frame];
UIImage *tabBarBackgroundImage = [UIImage imageNamed:@"fasha-down.png"];
UIColor *color = [[UIColor alloc] initWithPatternImage:tabBarBackgroundImage];


[viewa setBackgroundColor:color];
[[tabBarController tabBar] insertSubview:viewa atIndex:0];
[color release];
[viewa release];
[window addSubview:tabBarController.view]; 
}

感谢您的帮助

【问题讨论】:

    标签: iphone xcode image background ios5


    【解决方案1】:
    // Change the tab bar background
    UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar.png"];
    [[UITabBar appearance] setBackgroundImage:tabBarBackground];
    

    【讨论】:

      【解决方案2】:

      如下更改来源,您可以解决此问题。

      旧来源:

      [[tabBarController tabBar] insertSubview:viewa atIndex:0];
      

      新来源:

      //1.Check version of iOS
      if(iOSVersion <= 4.3){
          [[tabBarController tabBar] insertSubview:viewa atIndex:0];
      }else{
      //iOS5
          [[tabBarController tabBar] insertSubview:viewa atIndex:1];
      }
      

      【讨论】:

      • 非常感谢!你省了我很多麻烦
      • iOSVersion 不是变量的框架。您需要创建用于检查 iOS 版本的源代码。参考链接:查看 iPhone iOS 版本
      【解决方案3】:

      使用此代码检测 iOS 版本

      if ([[[UIDevice currentDevice] systemVersion] floatValue] < 5)  {
          [[tabBarController tabBar] insertSubview:viewa atIndex:0];
      }else{
          [[tabBarController tabBar] insertSubview:viewa atIndex:1];
      }
      

      【讨论】:

        猜你喜欢
        • 2014-06-23
        • 2011-07-11
        • 2021-07-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多