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];
}

代码效果:


Simulator Screen Shot 2017年2月23日 下午11.02.14.png
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,084评论 19 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,111评论 25 709
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,639评论 4 61
  • 最近几周才思枯竭,通常很久写不出一篇文章,每每打卡都是最后才交。也下定决心,绝不拖延,但总是给自己找借口,拖到最后...
    蘑菇团团阅读 1,499评论 0 1
  • 0. 这篇文章的开头在我早起60+天的时候就开始构思了。 我想了一些特别激励的话,比如“生而为赢”;比如“酷暑到寒...
    涂俊杰c阅读 4,042评论 0 1

友情链接更多精彩内容