iOS tabbar+navgation的项目结构
2018-08-21 本文已影响0人
yuezishenyou
1.AppDelegate.m
self.window.frame = [[UIScreen mainScreen] bounds];
self.window.backgroundColor = [UIColor whiteColor];
XGGTabBarController *navc = [[XGGTabBarController alloc] init];
self.window.rootViewController = navc;
[self.window makeKeyAndVisible];
2.UITabBarController.m
- (void)viewDidLoad {
[super viewDidLoad];
// 设置标题字体颜色
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor blackColor]} forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor orangeColor]} forState:UIControlStateSelected];
// 设置标题字体大小
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:8.0]} forState:UIControlStateNormal];
[self addChildVC:[[XGGMainController alloc]init] title:@"主页" normalImage:@"friendsRecommentIcon" selectedImage:@"friendsRecommentIcon-click"];
[self addChildVC:[[XGGRealmController alloc]init] title:@"其他" normalImage:@"MainTagSubIcon" selectedImage:@"MainTagSubIconClick"];
[self addChildVC:[[XGGViewController alloc]init] title:@"这个" normalImage:@"nav_coin_icon" selectedImage:@"nav_coin_icon_click"];
}
- (void)addChildVC:(UIViewController *)controller title:(NSString *)title normalImage:(NSString *)normalImage selectedImage:(NSString *)selectedImage
{
UINavigationController *navc = [[UINavigationController alloc] initWithRootViewController:controller];
navc.tabBarItem.title = title;
navc.tabBarItem.image = [[UIImage imageNamed:normalImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
navc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
controller.navigationItem.title = title;
[self addChildViewController:navc];
}
3.ViewController.m
// self.title = @"主页";
self.navigationItem.title = @"主页";