UItabbar 去掉高亮和定制背景色


IOS5.0+


  if ([Utilities deviceVersion] >= 5.0) {

    [self.tabBarsetTintColor:[UIColorcolorWithRed:38/255.0green:38/255.0blue:38/255.0alpha:1.0]];

    [self.tabBarsetSelectionIndicatorImage:UIIMAGE_FROMPNG(@"bg_touming")];

  }



<5.0



- (void)setSelectedIndex:(NSUInteger)index

{

  [supersetSelectedIndex:index];

  [selfsetNoHighlightTabBar];

}


- (void)setSelectedViewController:(UIViewController *)selectedViewController

{

  [super setSelectedViewController:selectedViewController];

  [selfsetNoHighlightTabBar];

}





- (void)setNoHighlightTabBar

{

  int tabCount = [self.viewControllerscount] > 5 ? 5 : [self.viewControllerscount];

  NSArray * tabBarSubviews = [self.tabBarsubviews];

  for(int i = [tabBarSubviewscount] - 1; i > [tabBarSubviews count] - tabCount - 1; i--)

  {

    for(UIView * v in [[tabBarSubviews objectAtIndex:i] subviews])

    {

      if(v && [NSStringFromClass([vclass]) isEqualToString:@"UITabBarSelectionIndicatorView"])

      {//the v is the highlight view.

        [v removeFromSuperview];

        break;

      }

    }

  }

}



定制背景色:


在 viewdidload里面添加


- (void)customizeTabarBackgroud

{

  CGRect frame = self.tabBar.frame;

  frame.origin.x = 0;

  frame.origin.y = 0;

  UINavigationBar * bgView4TabBar = [[UINavigationBar allocinitWithFrame:frame];

  bgView4TabBar.tintColor = [UIColor colorWithRed:38/255.0 green:38/255.0 blue:38/255.0 alpha:1.0]; 

  [self.tabBar insertSubview:bgView4TabBar atIndex:[[[UIDevice currentDevicesystemVersionintValue]<5?0:1];

  [bgView4TabBar release];


}

你可能感兴趣的:(UItabbar 去掉高亮和定制背景色)