[IOS]代碼創建UINavigationController+UITabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
   //初始化所有的子控制器
    //首頁
    IWHomeViewController *home=[[IWHomeViewController alloc]init];
    home.view.backgroundColor=[UIColor whiteColor];
   [self setupChildViewController:home title:@"首頁" imageName:@"tabbar_home" selectedImgName:@"tabbar_home_selected"];
    //消息
    IWMessageViewController *message=[[IWMessageViewController alloc]init];
    message.view.backgroundColor=[UIColor whiteColor];
    [self setupChildViewController:message title:@"消息" imageName:@"tabbar_message_center" selectedImgName:@"tabbar_message_center_selected"];
    //廣場
    IWdiscoverViewController *discover=[[IWdiscoverViewController alloc]init];
    discover.view.backgroundColor=[UIColor whiteColor];
     [self setupChildViewController:discover title:@"廣場" imageName:@"tabbar_discover" selectedImgName:@"tabbar_discover_selected"];
  //我
    IWHomeViewController *mine=[[IWHomeViewController alloc]init];
    mine.view.backgroundColor=[UIColor whiteColor];
     [self setupChildViewController:mine title:@"我" imageName:@"tabbar_profile" selectedImgName:@"tabbar_profile_selected"];
 
}
/**
 *  初始化子控制器
 *
 *  @param childVc           viewcontroller
 *  @param title             標題
 *  @param imageName         圖片名字
 *  @param selectedImageName 選擇的圖片名字
 */
-(void)setupChildViewController:(UIViewController *)childVc title:(NSString *) title imageName:(NSString *)imageName selectedImgName:(NSString *)selectedImageName
{
    
    childVc.view.backgroundColor=[UIColor whiteColor];
    childVc.title=title;
    childVc.tabBarItem.image=[UIImage imageNamed:imageName];
    childVc.tabBarItem.selectedImage=[[UIImage imageNamed:selectedImageName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:childVc];
    [self addChildViewController:nav];
    
}
<img src="https://img-blog.csdn.net/20141206203422573?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdzI1MDEzMDI1NQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
發佈了30 篇原創文章 · 獲贊 7 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章