UITabBarController的一些事

设置tabbar选中颜色

    //UITabBar的选中颜色的设置
    [UITabBar appearance].tintColor = [UIColor purpleColor];

设置文字颜色

 NSDictionary * attritext = @{NSForegroundColorAttributeName:[UIColor colorWithRed:186/255.0 green:136.0/255.0 blue:42.0/255.0 alpha:1]};
   
 [[UITabBarItem appearance] setTitleTextAttributes:attritext forState:UIControlStateSelected];
  • 如果UITabBarController的子控制器是普通控制器,代码设置图片、title的方法是
   self.tabBarItem.title = @"袭击以来";
   self.tabBarItem.badgeValue = @"10";
   self.tabBarItem.image = [UIImage imageNamed:@"icon_mine2_red2"];
  • 如果UITabBarController的子控制器是导航栏控制武器
   self.navigationController.tabBarItem.title = @"袭击以来";
   self.navigationController.tabBarItem.badgeValue = @"10";
   self.navigationController.tabBarItem.image = [UIImage imageNamed:@"icon_mine2_red2"];
  • 在UITabBarController中去设置它的第n个子控制器的tabBarItem
    UIViewController * vc = self.childViewControllers[3];
    vc.tabBarItem.badgeValue = @"8";
    vc.tabBarItem.title = @"新名字";
  • 设置tabar的透明
/*
 Default is YES.
 You may force an opaque background by setting the property to NO.
 If the tab bar has a custom background image, the default is inferred from the alpha
 values of the image—YES if it has any pixel with alpha < 1.0
 If you send setTranslucent:YES to a tab bar with an opaque custom background image
 the tab bar will apply a system opacity less than 1.0 to the image.
 If you send setTranslucent:NO to a tab bar with a translucent custom background image
 the tab bar will provide an opaque background for the image using the bar's barTintColor if defined, or black
 for UIBarStyleBlack or white for UIBarStyleDefault if barTintColor is nil.
 */
self.tabBarController.tabBar.translucent = YES;

你可能感兴趣的:(UITabBarController的一些事)