Custom UITabBar background image not working in iOS 5 and later

后端 未结 5 2175
不思量自难忘°
不思量自难忘° 2020-12-01 11:13

I have a simple piece of code that places a background image on the tabBar.

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@         


        
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-01 11:56

    After reviewing various articles, I found the answer for anyone that's having the same problem:

    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tabBG.png"]];
    
    if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) {
        //iOS 5
        [self.tabBarController.tabBar insertSubview:imageView atIndex:1];
    }
    else {
        //iOS 4.whatever and below
        [self.tabBarController.tabBar insertSubview:imageView atIndex:0];
    }
    
    [imageView release];
    

    Works like a charm! Enjoy.

提交回复
热议问题