1

嗨,我正在自定义标签栏中开发,我的部署目标是 iOS4

在此处输入图像描述

在 iOS5 明智的一切都很好。

在 iOS4 明智地不工作

代码片段

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tabBack.png"]];

if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) {
    //iOS 5
    [self.tabBarController.tabBar insertSubview:imageView atIndex:1];
   self.tabBarController.tabBar.selectionIndicatorImage =[UIImage     imageNamed:@"red_Back.png"];
    [[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];

}
else {
    //iOS 4
    [self.tabBarController.tabBar insertSubview:imageView atIndex:0];
}

我尝试了一些代码

1) 有没有办法为 UITabBarItem 使用自定义选择的图像?

2) 为 iPhone 应用程序创建自定义 UITabBar 真的很酷吗?

对那些代码示例没有影响

我尝试了很多,有什么方法可以在 iOS4 中完成这项任务?

有什么捷径吗?

任何教程或示例请

提前致谢

4

1 回答 1

0

最初检查屏幕尺寸

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    NSInteger tabbarHeight;
    CGRect Bounds = [[UIScreen mainScreen] bounds];
    if (Bounds.size.height == 568) {
        // code for 4-inch screen
        tabbarHeight = 519;
              } else {
        // code for 3.5-inch screen
        tabbarHeight = 431;
     }


    UITabBarController *tabBarController = [[UITabBarController alloc]init];
    tabBarController.selectedIndex=0;
    tabBarController.delegate=self;
    img = [[UIImageView alloc]init];
    img.image=[UIImage imageNamed:@"Tabimage.png"];
    img.frame=CGRectMake(0,tabbarHeight, 320, 49);         
    [self.tabBarController.view addSubview:img];    
    tabBarController.viewControllers = @[homeNavigationController,profileNavigationControler,notificationNavigationController,newsNavigationController,aboutUsNavigationController];
     self.window.rootViewController = self.tabBarController;    
    [self.window makeKeyAndVisible];
    return YES;
 }

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    NSUInteger index=[[tabBarController viewControllers] indexOfObject:viewController];
    switch (index) {
        case 0:
            self.img.image=[UIImage imageNamed:@"Tabone.png"];
            break;
        case 1:
            self.img.image=[UIImage imageNamed:@"Tabtwo.png"];
            break;
        case 2:
            self.img.image=[UIImage imageNamed:@"Tabthree.png"];
            break;
        case 3:
            self.img.image=[UIImage imageNamed:@"Tabfour.png"];
            break;
        case 4:
            self.img.image=[UIImage imageNamed:@"Tabfive.png"];
            break;
        default:
            break;
    }
    return YES;
 }
于 2013-03-15T10:25:36.133 回答