为了解决:UITabBarController 显示不按照系统的样式走,按照自己的意愿来显示出来
步骤:
1:定义UITabBarController :
UITabBarController *tabBarController = [[UITabBarController alloc]initWithNibName:nil bundle:nil];
tabBarController.viewControllers = [[NSArray alloc] initWithObjects:oneNav,twoNav,threeNav,fourNav, nil];
// 得到UITabBar
UITabBar *tabBar = tabBarController.tabBar;
// 得到每个UITabBarItem
UITabBarItem *aTabBarItem = [tabBar.items objectAtIndex:0];
UITabBarItem *bTabBarItem = [tabBar.items objectAtIndex:1];
UITabBarItem *cTabBarItem = [tabBar.items objectAtIndex:2];
UITabBarItem *dTabBarItem = [tabBar.items objectAtIndex:3];
aTabBarItem.title = @"aaa";
bTabBarItem.title = @"bbb";
cTabBarItem.title = @"ccc";
dTabBarItem.title = @"ddd";
// 选中与不选中的小图片
[aTabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"tab_featured_seclected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_featured"]];
[bTabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"tab_free_seclected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_free"]];
[cTabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"tab_top_seclected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_top"]];
[dTabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"tab_more_seclected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_more"]];
UIImage* tabBarBackground = [self scaleImage:[UIImage imageNamed:@"top_bg.png"]];
// 修改UITabBar的背景颜色
[[UITabBar appearance] setBackgroundImage:[tabBarBackground resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeStretch]];
// 修改选中后的背景图
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"btnadd3"]];
// 字体的在正常情况下的显示颜色
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
nil] forState:UIControlStateNormal];
// 字体在选中情况下的显示颜色
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor blueColor], UITextAttributeTextColor,
nil] forState:UIControlStateSelected];