12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- //
- // MyTabbarController.m
- // LNManager
- //
- // Created by EchoShacolee on 2017/4/6.
- // Copyright © 2017年 lee. All rights reserved.
- //
- #import "MyTabbarController.h"
- #import "MyUINavigationController.h"
- #import "WillDoVC.h"
- #import "JobVC.h"
- #import "WaringVC.h"
- //#import "statisticsVC.h"
- #import "MeCenterVC.h"
- @interface MyTabbarController ()
- @end
- @implementation MyTabbarController
- - (void)addControllers
- {
- //创建要管理的子视图控制器
- NSArray *titles = @[@[@"消息",@"tabbar_1",@"tabbar_1_H"],
- @[@"功能",@"tabbar_2",@"tabbar_2_H"],
- @[@"预警",@"tabbar_3",@"tabbar_3_H"],
- @[@"个人",@"tabbar_4",@"tabbar_4_H"]];
- NSArray *vcName = @[@"WillDoVC",@"JobVC",@"WaringVC",@"MeCenterVC"];
- NSMutableArray *controllers = [NSMutableArray array];
- for (NSInteger i=0; i<titles.count; i++) {
-
- Class cls = NSClassFromString(vcName[i]);
- UIViewController *bvc = [[cls alloc] init];
- MyUINavigationController * naVC = [[MyUINavigationController alloc]initWithRootViewController:bvc];
-
- //创建item
- //正常状态图片
- UIImage *image = [[UIImage imageNamed:titles[i][1]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
- //选中状态图片
- UIImage *selectedImage = [[[UIImage imageNamed:titles[i][1]] tint:COLOR_THEME] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
-
- UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:titles[i][0] image:image selectedImage:selectedImage];
-
- bvc.tabBarItem = item;
-
- //保存到数组中
- [controllers addObject:naVC];
- }
- //统一设置tabBarItem的标题属性
- // UIColor *color = [UIColor colorWithRed:39/255.0 green:38/255.0 blue:54/255.0 alpha:1.0];
- [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:COLOR_THEME} forState:UIControlStateSelected];
-
-
- //设置所管理的视图控制器
- self.viewControllers = controllers;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- self.tabBar.backgroundColor = [UIColor colorWithRed:222 / 250.0 green:222 / 250.0 blue:222 / 250.0 alpha:1.0];
- [self addControllers];
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|