TabBarController添加子控制器
- (void)setupChildVC {
NSArray *childItemsArray = @[
@{ZXSClassKey:@"ZXSMessageController",
ZXSTitleKey:@"微信",
ZXSImageKey:@"tabbar_mainframe",
ZXSSelectedImageKey:@"tabbar_mainframeHL"},
@{ZXSClassKey:@"ZXSContactController",
ZXSTitleKey:@"通讯录",
ZXSImageKey:@"tabbar_contacts",
ZXSSelectedImageKey:@"tabbar_contactsHL"},
@{ZXSClassKey:@"ZXSDiscoverController",
ZXSTitleKey:@"发现",
ZXSImageKey:@"tabbar_discover",
ZXSSelectedImageKey:@"tabbar_discoverHL"},
@{ZXSClassKey:@"ZXSMeController",
ZXSTitleKey:@"我",
ZXSImageKey:@"tabbar_me",
ZXSSelectedImageKey:@"tabbar_meHL"}
];
[childItemsArray enumerateObjectsUsingBlock:^(NSDictionary *dict, NSUInteger idx, BOOL *stop) {
UIViewController *vc = [[NSClassFromString(dict[ZXSClassKey]) alloc] init];
vc.title = dict[ZXSTitleKey];
ZXSBaseNavigationController *nav = [[ZXSBaseNavigationController alloc] initWithRootViewController:vc];
UITabBarItem *item = nav.tabBarItem;
item.title = dict[ZXSTitleKey];
[item setTitleTextAttributes:@{NSForegroundColorAttributeName : ZXSTintColor} forState:UIControlStateSelected];
item.image = [UIImage imageNamed:dict[ZXSImageKey]];
item.selectedImage = [[UIImage imageNamed:dict[ZXSSelectedImageKey]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[self addChildViewController:nav];
}];
}
统一设置导航栏
+ (void)load {
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
UINavigationBar *navigationBar = [UINavigationBar appearance];
navigationBar.barTintColor = [UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:0.9];
navigationBar.tintColor = [UIColor whiteColor];
navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
}
网友评论