IOS-导航控制器和工具栏

关于IOS的导航控制器和工具栏 是IOS开发中一定会用到的知识,好在苹果给开发者们封装好了 导航控制器的样式。使开发者运用起来非常方便。

个人觉得IOS的TabBar比android的要简单的多(-----此处废话)

1、定义好n个视图文件

-

2、在APP2AppDelegate.m文件里设置根视图 看代码

#import "DongtaiView.h"
#import "MessageView.h"
#import "XiaoyouView.h"
#import "ThreeYearViewr.h"
#import "ClubView.h"
#import "OtherViewr.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    //UITabBar 选项卡
    //UITabBarItem 每一个选项
    //通过UITabBar来显示 UITabBarItem的实例
    
    //实例化视图控制器
    DongtaiView *dongtaiVC = [[DongtaiViewr alloc] init];
    //定义每一个选项 使用系统图标
    //UITabBarItem *dtItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:1];
    UINavigationController *navDongtai = [[UINavigationController alloc] initWithRootViewController:dongtaiVC];
    //自定义图片
    UITabBarItem *dtItem = [[UITabBarItem alloc] initWithTitle:@"动态" image:[UIImage imageNamed:@"0157"] tag:1];
    
    navDongtai.tabBarItem = dtItem;
    [dtItem release];
    
    //显示消息选项
    MessageView *msgVc = [[MessageView alloc] init];
    UINavigationController *navMsg = [[UINavigationController alloc] initWithRootViewController:msgVc];
    //定义每一个选项
    UITabBarItem *msgItem = [[UITabBarItem alloc]initWithTitle:@"消息" image:[UIImage imageNamed:@"0013"] tag:2];
    navMsg.tabBarItem = msgItem;
    [msgItem release];
    
    
    //显示校友选项
    XiaoyouView *xiaoyouVc = [[XiaoyouViewr alloc] init];
    UINavigationController *navXiaoyou = [[UINavigationController alloc] initWithRootViewController:xiaoyouVc];
    //定义每一个选项
    UITabBarItem *xiaoyouItem = [[UITabBarItem alloc]initWithTitle:@"校友" image:[UIImage imageNamed:@"0011"] tag:3];
    navXiaoyou.tabBarItem = xiaoyouItem;
    [xiaoyouItem release];
    
    //显示CSDN三年选项
    ThreeYearViewr *threeyearVc = [[ThreeYearView alloc] init];
    UINavigationController *navThreeYear = [[UINavigationController alloc] initWithRootViewController:threeyearVc];
    //定义每一个选项
    UITabBarItem *threeyearItem = [[UITabBarItem alloc]initWithTitle:@"CSDN三年" image:[UIImage imageNamed:@"0151"] tag:4];
    navThreeYear.tabBarItem = threeyearItem;
    [threeyearItem release];
    
    //显示俱乐部选项
    ClubView *clubVc = [[ClubViewr alloc] init];
    UINavigationController *navClub = [[UINavigationController alloc] initWithRootViewController:clubVc];
    //定义每一个选项
    UITabBarItem *clubItem = [[UITabBarItem alloc]initWithTitle:@"高校俱乐部" image:[UIImage imageNamed:@"0300"] tag:5];
    navClub.tabBarItem = clubItem;
    [clubItem release];
    
    //显示俱乐部选项
    OtherViewr *otherVc = [[OtherView alloc] init];
    UINavigationController *navOther = [[UINavigationController alloc] initWithRootViewController:otherVc];
    //定义每一个选项
    UITabBarItem *otherItem = [[UITabBarItem alloc]initWithTitle:@"其他" image:[UIImage imageNamed:@"0233"] tag:6];
    navOther.tabBarItem = otherItem;
    [otherItem release];
    
    //定义数组
    NSArray *arrVc =@[navDongtai,navMsg,navXiaoyou ,navThreeYear,navClub,navOther];
    
    //定义UITabBarController
    UITabBarController *tabBar = [[UITabBarController alloc] init];
    tabBar.viewControllers = arrVc;
  
    
  //注意要把当前的tabBar 设置为根视图,这样才能保我们切换那一个view这个工具栏都存在
    
    self.window.rootViewController = tabBar;
    
    [dongtaiVC release];
    [msgVc release];
    [navMsg release];
    [xiaoyouVc release];
    [threeyearVc release];
    [clubVc release];
    [otherVc release];
    [navDongtai release];
    [navClub release];
    [navOther release];
    [navThreeYear release];
    [navXiaoyou release];
    
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}
3、在各个分视图中定义显示的view 如:

在DongtaiView.m中 重写父类的loadView方法

-(void)loadView{


    UIView *baseView = [[UIView alloc]initWithFrame:[UIScreen mainScreen].applicationFrame];
    baseView.backgroundColor = [UIColor redColor];
    self.view = baseView;
    [baseView release];


}

其他的分栏也是这样。

OK就是这样。别看整个项目的文件和代码不少,但是大多是重复操作。因为苹果已经开发者铺好了路,我们照着走就行了。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值