iOS 多个 tab 页 demo

本文介绍了一种在iOS应用中创建多tab页的实践,以实现清晰的功能模块划分,促进团队协作。文章包含简介、关键代码片段及demo截图。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

简介

在日常的开发中,App 中多个功能模块常常表现为多个 tab 页的形式,利用 tab 页,可以使得 App 的功能模块非常清晰,同时又非常有利于团队的协作开发。本文记录了这样一个 demo 的示例代码。

代码

/**
 * the codes support iOS 7.0 and later iOS version.
 *
 */ 


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    UITabBarController *tabBarController = [[UITabBarController alloc] init];

    UIImage *unselecteImage = [[UIImage imageNamed:@"01"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];//采用图片的原始格式,系统不对图片进行处理

    UIImage *selectedImage = [[UIImage imageNamed:@"02"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    ViewController *vc1 = [[ViewController alloc] init];
    vc1.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"微信" image:unselecteImage selectedImage:selectedImage];
    //...

    ViewControllerTwo *vc2 = [[ViewControllerTwo alloc] init];
    vc2.title = @"通讯录";
    //设置选中和未选中的图片...

    ViewControllerThree *vc3 = [[ViewControllerThree alloc] init];
    vc3.title = @"发现";
    //...

    ViewControllerFour *vc4 = [[ViewControllerFour alloc] init];
    vc4.title = @"我";
    //...

    NSArray *viewControllers = [NSArray arrayWithObjects:vc1, vc2, vc3, vc4, nil];
    tabBarController.viewControllers = viewControllers;

    UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:tabBarController];


    self.window.rootViewController = nc;
    [self.window setTintColor:[UIColor greenColor]];


    [self.window makeKeyAndVisible];

    return YES;
}

demo 截图

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值