zoukankan      html  css  js  c++  java
  • 【iOS开发-78】用代码实现UITabBarController+UINavigationController


    #import "WPTabBarController.h"
    #import "WPFirstViewController.h"
    #import "WPSecondViewController.h"
    #import "WPThirdViewController.h"
    #import "WPFourthViewController.h"
    
    @interface WPTabBarController ()
    
    @end
    
    @implementation WPTabBarController
    
    - (void)viewDidLoad {
        WPFirstViewController *firsVc=[[WPFirstViewController alloc]init];
        WPSecondViewController *secondVc=[[WPSecondViewController alloc]init];
        WPThirdViewController *thirdVc=[[WPThirdViewController alloc]init];
        WPFourthViewController *fourthVc=[[WPFourthViewController alloc]init];
        
        //下面两种方式均可设置tabbar上得标题
        firsVc.tabBarItem.title=@"消息";
        //firsVc.title=@"消息";
        secondVc.tabBarItem.title=@"联系人";
        //secondVc.title=@"联系人";
        thirdVc.tabBarItem.title=@"动态";
        //thirdVc.title=@"动态";
        fourthVc.tabBarItem.title=@"设置";
        //fourthVc.title=@"设置";
    
        //设置icon
        firsVc.tabBarItem.image=[UIImage imageNamed:@"tab_recent_nor"];
        secondVc.tabBarItem.image=[UIImage imageNamed:@"tab_buddy_nor"];
        thirdVc.tabBarItem.image=[UIImage imageNamed:@"tab_qworld_nor"];
        fourthVc.tabBarItem.image=[UIImage imageNamed:@"tab_me_nor"];
        
        firsVc.view.backgroundColor=[UIColor redColor];
        secondVc.view.backgroundColor=[UIColor whiteColor];
        thirdVc.view.backgroundColor=[UIColor purpleColor];
        fourthVc.view.backgroundColor=[UIColor greenColor];
        
        
        //用下面方式加入子控制器
        //self.viewControllers=@[firsVc,secondVc,thirdVc,fourthVc];
        [self addChildViewController:firsVc];
        [self addChildViewController:secondVc];
        [self addChildViewController:thirdVc];
        [self addChildViewController:fourthVc];
        
        [super viewDidLoad];
        // Do any additional setup after loading the view.
    }

    核心:

    ——定义1个tabBat控制器和4个导航控制器。然后通过addChildViewController或者数组的形式把4个导航控制器加到tabBar控制器中。

    ——每一个导航控制器通过tabBarItem属性来设置标题和icon等。

    界面截屏:



  • 相关阅读:
    linux:centos7开启指定端口,开放外网访问
    zookeeper 集群搭建
    单机安装zookeeper的3.4.7版本
    CentOS7下安装jdk1.8并配置环境变量,防火墙设置开关
    Redis分布式锁的正确实现方式
    MySQl5.7 忘记密码怎么办?
    Flink 之Window(窗口)
    Flink之Sink(文件、Kafka、Redis、Es、Mysql)
    Canal同步Mysql数据至Hbase
    Flink 之分流Select与Split
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/7091431.html
Copyright © 2011-2022 走看看