- (void)setChildViewController:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
vc.tabBarItem.title = title;
if ([vc isKindOfClass:[XMNewFateViewController class]]) {
vc.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
}
if (iOS7) {
vc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
if (boolZhi) {// 图片图层原因
vc.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}
else{
vc.tabBarItem.image = [UIImage imageNamed:image];
}
} else {
vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
vc.tabBarItem.image = [UIImage imageNamed:image];
}
NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
textAttrs[NSForegroundColorAttributeName] =boolZhi?[UIColor colorWithRed:247/255.0 green:186.0/255.0 blue:18/255.0 alpha:1.0]:[UIColor colorWithRed:123/255.0 green:123/255.0 blue:123/255.0 alpha:1.0];
textAttrs[NSFontAttributeName] = LightFont(13);//默认
NSMutableDictionary *selectTextAttrs = [NSMutableDictionary dictionary];
selectTextAttrs[NSForegroundColorAttributeName] = boolZhi?[UIColor clearColor]:ZYColor(@"#FF3455");//
selectTextAttrs[NSFontAttributeName] = LightFont(13);
[vc.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
[vc.tabBarItem setTitleTextAttributes:selectTextAttrs forState:UIControlStateSelected];
UIView *bgView = [[UIView alloc] initWithFrame:self.tabBar.bounds];
bgView.backgroundColor = boolZhi?[UIColor colorWithPatternImage:[UIImage imageNamed:@"n11_label"]]:[UIColor whiteColor];//:@"tabBgImage"]
bgView.alpha = 1;//boolZhi?1:0.3;
[self.tabBar insertSubview:bgView atIndex:0];
self.tabBar.opaque = YES;
ZYNavigationController *zyNav = [[ZYNavigationController alloc]initWithRootViewController:vc];
[self addChildViewController:zyNav];
}
-(void)tabBarController:(UITabBarController*)tabBarController didSelectViewController:(UIViewController *)viewController{
for (UIViewController * childrenVC in tabBarController.childViewControllers) {
if(childrenVC== tabBarController.childViewControllers[tabBarController.selectedIndex]) {
childrenVC.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0);
}else{
childrenVC.tabBarItem.imageInsets = UIEdgeInsetsMake(0, 0, 0, 0);
}
}
}