Custom UITabBar background image not working in iOS 5 and later

后端 未结 5 2176
不思量自难忘°
不思量自难忘° 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:53

    //---- For providing background image to tabbar
    
    UITabBar *tabBar = [tabBarController tabBar];
    if ([tabBar respondsToSelector:@selector(setBackgroundImage:)])
    {
        // ios 5 code here
        [tabBar setBackgroundImage:[UIImage imageNamed:@"PB_MD_footer_navBg_v2.png"]];
    
    }
    else
    {
        // ios 4 code here
    
        CGRect frame = CGRectMake(0, 0, 480, 49);
        UIView *tabbg_view = [[UIView alloc] initWithFrame:frame];
        UIImage *tabbag_image = [UIImage imageNamed:@"PB_MD_footer_navBg_v2.png"];
        UIColor *tabbg_color = [[UIColor alloc] initWithPatternImage:tabbag_image];
        tabbg_view.backgroundColor = tabbg_color;
        [tabBar insertSubview:tabbg_view atIndex:0];
    
    }
    

提交回复
热议问题