正文
@interface XBYTabBarController ()
@end
@implementation XBYTabBarController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self addAllChildControllers];
[self setupAllTabBarItem];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)addAllChildControllers{
ViewController *vc = [ViewController new];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:vc];
[self addChildViewController:nav1];
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:vc];
[self addChildViewController:nav2];
UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:vc];
[self addChildViewController:nav3];
UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:vc];
[self addChildViewController:nav4];
}
-(void)setupAllTabBarItem {
NSArray *title = @[@"1",@"2",@"3",@"4"];
NSArray *image = @[@"1",@"2",@"3",@"4"];
for (int i = 0;i<self.childViewControllers.count;i++){
UINavigationController *nav = self.childViewControllers[i];
nav.tabBarItem.title = title[i];
nav.tabBarItem.image = [UIImage imageNamed:image[i]];
nav.tabBarItem.selectedImage = [UIImage imageNamed:image[i]];
NSMutableDictionary *mDic = [NSMutableDictionary dictionary];
mDic[NSForegroundColorAttributeName] = [UIColor redColor];
//可以设置字体大小、颜色、阴影、空心图文混排等,详见NSAttributedString.h文件
[nav.tabBarItem set