iOS tabbar 控制器基本使用
RootViewController *rootVC=[[RootViewController alloc] init] SignInViewController *signVC = [[SignInViewController alloc]init]; //如果在这里指定tabitem标题,则在FirstViewController中指定self.tabBarItem.title则不生效 signVC.title = @"打卡"; UITabBarItem *signItem = [[UITabBarItem alloc]initWithTitle:@"打卡" image:nil tag:1]; [signItem setFinishedSelectedImage:[UIImage imageNamed:@"p1"] withFinishedUnselectedImage:[UIImage imageNamed:@"p1_f"]]; signVC.tabBarItem = signItem; TextViewController *textVC = [[TextViewController alloc]init]; signVC.title = @"备注"; UITabBarItem *textItem = [[UITabBarItem alloc]initWithTitle:@"备注" image:nil tag:2]; [textItem setFinishedSelectedImage:[UIImage imageNamed:@"p1"] withFinishedUnselectedImage:[UIImage imageNamed:@"p1_f"]]; textVC.tabBarItem = textItem; VisitViewController *visitVC = [[VisitViewController alloc]init]; visitVC.title = @"拜访"; UITabBarItem *visitItem = [[UITabBarItem alloc]initWithTitle:@"拜访" image:nil tag:3]; [visitItem setFinishedSelectedImage:[UIImage imageNamed:@"p1"] withFinishedUnselectedImage:[UIImage imageNamed:@"p1_f"]]; visitVC.tabBarItem = visitItem; //构建UITabBarController并指定代理为本身 self.tabBarController = [[UITabBarController alloc]init]; self.tabBarController.delegate = self; //为UITabBarController添加TabBarItem self.tabBarController.viewControllers = [NSArray arrayWithObjects:textVC,signVC,visitVC, nil]; //设置选中哪个tab [self.tabBarController setSelectedIndex:1]; self.window.backgroundColor = [UIColor whiteColor]; //指定根视图 self.window.rootViewController = self.tabBarController;
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。