博客> iOS 自带tabbar的使用代码
iOS 自带tabbar的使用代码
2019-08-24 08:11 评论:0 阅读:348 Sherry_ssq
ios oc tabbar

NSArray* imgs = @[@"首页",@"发现",@"购物车",@"我的"];
    for (int i=0; i<4; i++) {
        UIViewController* vc = [[UIViewController alloc] init];
        UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:vc];
        //设置每个控制器的颜色
        nav.view.backgroundColor = randomColor;
        vc.navigationItem.title = [NSString stringWithFormat:@"%d",i];
        [nav.tabBarItem setTitle:@"123"];
        UIImage* itemImg = [UIImage imageNamed:imgs[i]];
        //做一下图片的渲染效果
        [nav.tabBarItem setImage:[itemImg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
        //设置字体颜色
        [nav.tabBarItem setTitleTextAttributes:@{ NSForegroundColorAttributeName:[UIColor redColor]}  forState:UIControlStateNormal];
        nav.tabBarItem.badgeValue = @"4";
        [self addChildViewController:nav];
收藏
0
sina weixin mail 回到顶部