手写代码搭建框架

TabBarController--4 * NavigationController (TabBarItem/ViewController)

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    firstViewController = [[FirstViewController alloc]init];
    UINavigationController *firstNav = [[UINavigationController alloc]initWithRootViewController:firstViewController];
    UITabBarItem* firstItem = [[UITabBarItem alloc]initWithTitle:@"aaa" image:[UIImage imageNamed:@"aaa"] tag:0];
    firstItem.selectedImage = [[UIImage imageNamed:@"aaa_p"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [firstNav setTabBarItem:firstItem];
    
    producesMainViewController = [[ProducesMainViewController alloc]initWithNibName:@"ProducesMainViewController" bundle:[NSBundle mainBundle]];
    UINavigationController *producesNav = [[UINavigationController  alloc]initWithRootViewController:producesMainViewController];
    UITabBarItem *productionItem = [[UITabBarItem alloc]initWithTitle:@"bob" image:[UIImage imageNamed:@"bbb"] tag:0];
    productionItem.selectedImage = [[UIImage imageNamed:@"bbb_p"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [producesNav setTabBarItem:productionItem];
    
    DailyAndInfoVC *informationVC = [[DailyAndInfoVC alloc]initWithNibName:@"DailyAndInfoVC" bundle:[NSBundle mainBundle]];
    UINavigationController *informationNav = [[UINavigationController  alloc]initWithRootViewController:informationVC];
    UITabBarItem *informationItem = [[UITabBarItem alloc]initWithTitle:@"ccc" image:[UIImage imageNamed:@"ccc"] tag:0];
    informationItem.selectedImage = [[UIImage imageNamed:@"ccc_p"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [informationNav setTabBarItem:informationItem];
    [informationItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:RGBCOLOR(153, 152, 152),NSForegroundColorAttributeName, [UIFont systemFontOfSize:13],NSFontAttributeName,nil] forState:UIControlStateNormal];
    [informationItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[StaticTools colorWithHexString:@"#d70031"],NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
    
    myselfViewController = [[MyselfViewController alloc]init];
    UINavigationController *myselfNav = [[UINavigationController alloc]initWithRootViewController:myselfViewController];
    UITabBarItem *myselfItem = [[UITabBarItem alloc]initWithTitle:@"ddd" image:[UIImage imageNamed:@"ddd"] tag:0];
    myselfItem.selectedImage = [[UIImage imageNamed:@"ddd_p"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    [myselfNav setTabBarItem:myselfItem];
    
    [firstItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:RGBCOLOR(153, 152, 152),NSForegroundColorAttributeName, [UIFont systemFontOfSize:13],NSFontAttributeName,nil] forState:UIControlStateNormal];
    [productionItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:RGBCOLOR(153, 152, 152),NSForegroundColorAttributeName, [UIFont systemFontOfSize:13],NSFontAttributeName,nil] forState:UIControlStateNormal];
    [myselfItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:RGBCOLOR(153, 152, 152),NSForegroundColorAttributeName, [UIFont systemFontOfSize:13],NSFontAttributeName,nil] forState:UIControlStateNormal];
    
    [firstItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[StaticTools colorWithHexString:@"#d70031"],NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
    [productionItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[StaticTools colorWithHexString:@"#d70031"],NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
    [myselfItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[StaticTools colorWithHexString:@"#d70031"],NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
    
    self.tabBarController = [[UITabBarController alloc]init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:firstNav,producesNav,informationNav,myselfNav, nil];
    
    self.tabBarController.selectedIndex = 0;
    self.tabBarController.delegate = self;
    self.tabBarController.view.frame = self.view.frame;
    [self.view addSubview:self.tabBarController.view];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容