本文共 2169 字,大约阅读时间需要 7 分钟。
前言:因为常用,所以我就备份到这里,然后如果需要修改,可以根据需求进行相关的更改。
1 @implementation YMTabBarController 2 3 - (void)viewDidLoad { 4 [super viewDidLoad]; 5 /**** 初始化一些设置 ****/ 6 [self setUp]; 7 8 /**** 添加子控制器 ****/ 9 [self addChildViewControllers];10 }11 - (void)setUp{12 13 }14 15 #pragma mark - 在load方法里全局设置所有UITabBarItem的文字属性16 // hy:配置全局设置属性 17 + (void)load18 {19 // UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil];20 // 普通状态下的文字属性21 // NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];22 // normalAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];23 // normalAttrs[NSForegroundColorAttributeName] = [UIColor colorWithHexString:@"#333333"];24 // [item setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];25 // 选中状态下的文字属性26 // NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];27 // selectedAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];28 // selectedAttrs[NSForegroundColorAttributeName] = [UIColor colorWithHexString:@"#23ac3a"];29 // [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected]; 30 }31 32 #pragma mark - 添加 导航控制器+子控制器33 - (void)addChildViewControllers{34 // 首页 35 [self setupOneChildViewController:[[MainViewController alloc] init] title:@"首页" image:@"" selectedImage:@""];36 37 // 我的 38 [self setupOneChildViewController:[[MineViewController alloc] init] title:@"我的" image:@"" selectedImage:@""];39 }40 41 #pragma mark - 私有方法42 /**43 * 初始化一个子控制器44 *45 * @param vc 子控制器46 * @param title 标题47 * @param image 图标48 * @param selectedImage 选中的图标49 */ 50 - (void)setupOneChildViewController:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage51 {52 YMNavigationController *nc = [[YMNavigationController alloc] initWithRootViewController:vc];53 // 设置导航控制器的标题54 // vc.navigationItem.title = title;55 // 设置tabBarItem的表诶 56 nc.tabBarItem.title = title;57 if (image.length) { // 图片名有具体值 58 nc.tabBarItem.image = [UIImage imageRenderingModeImageNamed:image];59 nc.tabBarItem.selectedImage = [UIImage imageRenderingModeImageNamed:selectedImage];60 }61 [self addChildViewController:nc];62 }63 64 @end
转载地址:http://myitl.baihongyu.com/