- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[self setWindow:[[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]];
[self.window makeKeyAndVisible];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.tabBar.backgroundColor = [UIColor yellowColor];
[self.window setRootViewController:tabBarController];
FirstViewController *firstVc = [[FirstViewController alloc] init];
firstVc.tabBarItem.title = @"首页";
firstVc.tabBarItem.image = [UIImage imageNamed:@"nav_icon_article_f"];
firstVc.tabBarItem.selectedImage = [UIImage imageNamed:@"nav_icon_article_p"];
UINavigationController *firstNc = [[UINavigationController alloc] initWithRootViewController:firstVc];
SecondViewController *second = [[SecondViewController alloc] init];
second.tabBarItem.title = @"选车";
second.tabBarItem.image = [[UIImage imageNamed:@"nav_icon_findcar_f"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
second.tabBarItem.selectedImage = [UIImage imageNamed:@"nav_icon_findcar_p"];
UINavigationController *secondNc = [[UINavigationController alloc] initWithRootViewController:second];
ThirdViewController *third = [[ThirdViewController alloc] init];
third.tabBarItem.title = @"选车";
third.tabBarItem.image = [UIImage imageNamed:@"nav_icon_forum_f"];
third.tabBarItem.selectedImage = [UIImage imageNamed:@"nav_icon_forum_p"];
UINavigationController *thirdNc = [[UINavigationController alloc]initWithRootViewController:third];
//设置tabbar的背景色
UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 49)];
backView.backgroundColor = [UIColor whiteColor];
[self.tabBar insertSubview:backView atIndex:0];
@implementation FirstViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = @"首页";
self.view.backgroundColor = [UIColor greenColor];
UIBarButtonItem *barButtom = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(hahh)];
self.navigationItem.rightBarButtonItem = barButtom;
}
- (void)hahh {
ForthViewController *forth = [[ForthViewController alloc] init];
//隐藏tabbar,跳转之前,由目标试图控制来设置这个参数
[forth setHidesBottomBarWhenPushed:true];
[self.navigationController pushViewController:forth animated:YES];
}
//设置选中、未选中的图标
//UIImageRenderingModeAlwaysOriginal 去掉系统默认的蓝色处理
childVc.tabBarItem.image = [[UIImage imageNamed:imageNmae] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];;
childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//设置选中、未选中的字体颜色
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateSelected];