2017.02.22

1.自定义tabBarController
1.1 设置tabBarItem的相关属性

/**
 设置tabBarItem的相关属性
 */
- (void)setupItemTextAttrs {
    
    //普通状态下的文字属性
    NSMutableDictionary *norAttrs = [[NSMutableDictionary alloc] init];
    norAttrs[NSForegroundColorAttributeName] = [UIColor grayColor];
    
    //选中状态下的文字属性
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    
    //统一设置UITabBarItem的属性
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:norAttrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
    
}

1.2 添加子控制器


/**
 添加子控制器
 */
- (void)setupChildVcs {
    
    [self setupOneChildVc:[[LXXEssenceViewController alloc] init] title:@"精华" image:@"tabBar_essence_icon" selectedImage:@"tabBar_essence_click_icon"];
    
    [self setupOneChildVc:[[LXXNewViewController alloc] init] title:@"新帖" image:@"tabBar_new_icon" selectedImage:@"tabBar_new_click_icon"];
    
    [self setupOneChildVc:[[LXXFriendTrendsViewController alloc] init] title:@"关注" image:@"tabBar_friendTrends_icon" selectedImage:@"tabBar_friendTrends_click_icon"];
    
    [self setupOneChildVc:[[LXXMeViewController alloc] init] title:@"我" image:@"tabBar_me_icon" selectedImage:@"tabBar_me_click_icon"];
    
}
/**
 设置tabBar
 */
- (void)setupOneChildVc:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    vc.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:image];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    [self addChildViewController:vc];
}

代码效果:


2017.02.22_第1张图片
Simulator Screen Shot 2017年2月23日 下午11.02.14.png

你可能感兴趣的:(2017.02.22)