IOS子UITabBarController效果

index:效果展示:

                                   IOS子UITabBarController效果_第1张图片



1.新建一个 UITabBarController作为根视图的子视图

2.新建4个表视图,作为UITabBarController的子视图如图



IOS子UITabBarController效果_第2张图片



3.UITabBarController的代码如下:


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    
    //首页
    //初始化一个视图控制器
    HomeViewController *home = [[HomeViewController alloc]init];
    //设置视图控制器背景颜色
    home.view.backgroundColor = [UIColor redColor];
    //设置标题
    home.title = @"首页";
    //设置该视图的tabbar的图标
    home.tabBarItem.image = [UIImage imageNamed:@"tabbar_home"];
    //为该视图添加导航控制器
    UINavigationController *homeNav = [[UINavigationController alloc]initWithRootViewController:home];
    //添加到父视图中
    [self addChildViewController:homeNav];
    
    //消息
    HomeViewController *message = [[HomeViewController alloc]init];
    message.view.backgroundColor = [UIColor blackColor];
    message.title = @"消息";
    message.tabBarItem.image = [UIImage imageNamed:@"tabbar_message_center"];
    UINavigationController *messageNav = [[UINavigationController alloc]initWithRootViewController:message];
    [self addChildViewController:messageNav];
    
    
    //广场
    HomeViewController *discover = [[HomeViewController alloc]init];
    discover.view.backgroundColor = [UIColor blueColor];
    discover.title = @"广场";
    discover.tabBarItem.image = [UIImage imageNamed:@"tabbar_discover"];
    
    UINavigationController *discoverNav = [[UINavigationController alloc]initWithRootViewController:discover];
    [self addChildViewController:discoverNav];
    
    //首页
    HomeViewController *me = [[HomeViewController alloc]init];
    me.view.backgroundColor = [UIColor greenColor];
    me.title = @"我";
    me.tabBarItem.image = [UIImage imageNamed:@"tabbar_profile"];
    UINavigationController *meNav = [[UINavigationController alloc]initWithRootViewController:me];
    [self addChildViewController:meNav];
}



由于代码过于冗余,时间仓促没来得及优化,谅解。。。

你可能感兴趣的:(IOS子UITabBarController效果)