ios更改UITabBarController背景以及选中背景图片的方法 以及隐藏tabbar

来源:互联网 发布:日向日足 知乎 编辑:程序博客网 时间:2024/05/17 21:48
一、背景图片
  1、5.0以上版本
     UIImage *image = [UIImage imageNamed:@"system_tabbar_bg.png"];
     [self.tabBar setBackgroundImage:image];
  2、5.0以下版本
     UIImage *image = [UIImage imageNamed:@"system_tabbar_bg.png"];
     NSArray *array = [self.view subviews];
     UITabBar *tabBar = [array objectAtIndex:1];

     tabBar.layer.contents = (id)image.CGImage;

二、隐藏tabbar

  1. -(void)makeTabBarHidden:(BOOL)hide {   
  2.      // Custom code to hide TabBar   
  3.      if ( [tabBarController.view.subviews count] < 2 ) {   
  4.           return;   
  5.      }   
  6.   
  7.      UIView *contentView;     
  8.      if ( [[tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] ) {   
  9.           contentView = [tabBarController.view.subviews objectAtIndex:1];   
  10.      } else {   
  11.           contentView = [tabBarController.view.subviews objectAtIndex:0];   
  12.      }   
  13.   
  14.      if (hide) {   
  15.           contentView.frame = tabBarController.view.bounds;   
  16.      } else {   
  17.           contentView.frame = CGRectMake(tabBarController.view.bounds.origin.x,                  
  18.                                          tabBarController.view.bounds.origin.y,   
  19.                                          tabBarController.view.bounds.size.width,   
  20.                                          tabBarController.view.bounds.size.height -   
  21.                                          tabBarController.tabBar.frame.size.height);   
  22.      }   
  23.   
  24.      tabBarController.tabBar.hidden = hide;   

0 0
原创粉丝点击