码迷,mamicode.com
首页 > 移动开发 > 详细

【iOS开发-78】用代码实现UITabBarController+UINavigationController

时间:2014-11-19 10:59:20      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   ar   color   os   on   2014   log   

bubuko.com,布布扣

#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等。

界面截屏:

bubuko.com,布布扣


【iOS开发-78】用代码实现UITabBarController+UINavigationController

标签:blog   http   io   ar   color   os   on   2014   log   

原文地址:http://blog.csdn.net/weisubao/article/details/41277519

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!