UITabBar -- 定制

- (void)viewDidLoad {
    [super viewDidLoad];

    tabBarViewController = [[UITabBarController alloc] init];
    tabBarViewController.view.backgroundColor = [UIColor blackColor];
    tabBarViewController.delegate = self;
    first = [[SceneListVC alloc] init];
    second = [[FavoriteVC alloc] init];
    
    [self addChildVc:first title:@"场景" image:@"场景未选中" selectedImage:@"场景选中"];
    [self addChildVc:second title:@"收藏" image:@"收藏未选中" selectedImage:@"收藏选中"];

    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:TAB_BAR_ITEM_TEXT_FONT, NSFontAttributeName, nil] forState:UIControlStateNormal];
    
    //ios 5+6
    [[UITabBar appearance] setTintColor:[UIColor blackColor]];
    //ios 7+
    [[UITabBar appearance] setBarTintColor:[UIColor blackColor]];
    tabBarViewController.tabBar.alpha = 0.8f;

    [self.view addSubview:tabBarViewController.view];
    [self.view bringSubviewToFront:tabBarViewController.view];

    

}





- (void)addChildVc:(UIViewController *)childVc title:(NSString *)title image:(NSString *)imageName selectedImage:(NSString *) selectedImageName{
    childVc.title = title;
    
    childVc.tabBarItem.image = [UIImage imageNamed:imageName];
    childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = [UIColor grayColor];
    textAttrs[NSFontAttributeName] = TAB_BAR_ITEM_TEXT_FONT;
    NSMutableDictionary *selectTextAttrs = [NSMutableDictionary dictionary];
    selectTextAttrs[NSForegroundColorAttributeName] = TAB_BAR_ITEM_TEXT_COLOR;
    selectTextAttrs[NSFontAttributeName] = TAB_BAR_ITEM_TEXT_FONT;
    [childVc.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    [childVc.tabBarItem setTitleTextAttributes:selectTextAttrs forState:UIControlStateSelected];
    
    NavigationVC *nav = [[NavigationVC alloc] initWithRootViewController:childVc];
    [tabBarViewController addChildViewController:nav];
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值