一、介绍

如今iOS开发过程中,最常见的一种UI架构是:界面底部是四五个tab bar 、中间是内容显示、顶部是包括标题及返回等操作button,当点击进入某个模块后可以点击进行返回。这样的架构的应用比較常见的如:微信、支付宝、京东、去哪儿等大部分应用都是这样的UI架构。下图所看到的:

二、创建方法

iOS开发SDK中提供了比較方便的类:UITabBarController、UINavigationController、UIViewController组合起来进行实现。

通常在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 。应用生命周期方法中完毕主UI架构的创建。

详细步骤为 :1、新建与tab bar个数一致的UIViewController 实例,初始化title,button等。

                      2、新建与tab bar个数一致UINavigationController实例,通过调用initWithRootViewController 分别赋给响应的UIViewController实例。

                      3、新建一个UITabBarController实例变量,然后给UITabBarController的viewControllers数组赋值为上面新建的多个UINavigationController实例。

4、把AppDelegate中的window属性的 rootViewController 设置为一个UITabBarController实例变量,

                      5、然后调用[self.window makeKeyAndVisible]方法显示界面。

三、详细实现代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {   

    self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];

    self.window.backgroundColor= [UIColor redColor];

    [self loadMainFrame];

    [self.window makeKeyAndVisible];

    return YES;

}

详细的实现位于loadMainFrame方法中

-(void)loadMainFrame{

    LOneViewController *oneController = [[LOneViewController alloc]init];

    UINavigationController *onNav = [[UINavigationController alloc]initWithRootViewController:oneController];

    oneController.tabBarItem.title=@"First";

    oneController.tabBarItem.image = [UIImage imageNamed:@"one.png"];

  LOneViewController *twoController = [[LOneViewController alloc]init];

    UINavigationController *twoNav = [[UINavigationController alloc]initWithRootViewController:oneController];

    twoController.tabBarItem.title=@"First";

    twoController.tabBarItem.image = [UIImage imageNamed:@"one.png"];

    LThreeViewController *threeController = [[LThreeViewController alloc]init];

    UINavigationController *threeNav = [[UINavigationController alloc]initWithRootViewController:threeController];

    threeNav.tabBarItem.title=@"Three";

    threeNav.tabBarItem.image=[UIImage imageNamed:@"three.png"];

    LFourViewController *fourController = [[LFourViewController alloc]init];

    UINavigationController *fourNav = [[UINavigationController alloc]initWithRootViewController:fourController];

    fourNav.tabBarItem.title=@"Four";

    fourNav.tabBarItem.image=[UIImage imageNamed:@"four.png"];

    fourNav.navigationBar.tintColor=[UIColor yellowColor];

    LFiveViewController *fiveController = [[LFiveViewController alloc]init];

    UINavigationController *fiveNav = [[UINavigationController alloc]initWithRootViewController:fiveController];

    fiveNav.navigationBar.tintColor=[UIColor yellowColor];

    fiveNav.tabBarItem.title=@"Five";

    fiveNav.tabBarItem.image=[UIImage imageNamed:@"five.png"];    

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

    [tabController setViewControllers:@[onNav,twoNav,threeNav,fourNav,fiveNav] ];

    self.window.rootViewController = tabController;

}

如上面代码所看到的:新建了四个UIViewController、以及四个UINavigationController,并把四个UIViewController设置为对应UINavigationController的rootViewController,然后把四个UINavigationController分别增加到UITabBarController的ViewControllers数组中。 然后设置 self.window.rootViewController为UITabBarController,最后    通过[self.window makeKeyAndVisible];方法完毕UI架构的创建。

iOS应用主流UI架构实现的更多相关文章

  1. iOS开发UI篇—APP主流UI框架结构

    iOS开发UI篇—APP主流UI框架结构 一.简单示例 说明:使用APP主流UI框架结构完成简单的界面搭建 搭建页面效果:                                二.搭建过程和 ...

  2. 谈谈UI架构设计的演化

    谈谈UI架构设计的演化 经典MVC 在1979年,经典MVC模式被提出. 在当时,人们一直试图将纯粹描述思维中的对象与跟计算机环境打交道的代码隔离开来,而Trygve Reenskaug在跟一些人的讨 ...

  3. IOS开发中UI编写方式——code vs. xib vs.StoryBoard

    最近接触了几个刚入门的iOS学习者,他们之中存在一个普遍和困惑和疑问,就是应该如何制作UI界面.iOS应用是非常重视用户体验的,可以说绝大多数的应用成功与否与交互设计以及UI是否漂亮易用有着非常大的关 ...

  4. 浅谈iOS中MVVM的架构设计与团队协作

    说到架构设计和团队协作,这个对App的开发还是比较重要的.即使作为一个专业的搬砖者,前提是你这砖搬完放在哪?不只是Code有框架,其他的东西都是有框架的,比如桥梁等等神马的~在这儿就不往外扯了.一个好 ...

  5. 【HELLO WAKA】WAKA iOS客户端 之二 架构设计与实现篇

    上一篇主要做了MAKA APP的需求分析,功能结构分解,架构分析,API分析,API数据结构分析. 这篇主要讲如何从零做iOS应用架构. 全系列 [HELLO WAKA]WAKA iOS客户端 之一 ...

  6. IOS中 浅谈iOS中MVVM的架构设计与团队协作

    今天写这篇文章是想达到抛砖引玉的作用,想与大家交流一下思想,相互学习,博文中有不足之处还望大家批评指正.本篇文章的内容沿袭以往博客的风格,也是以干货为主,偶尔扯扯咸蛋(哈哈~不好好工作又开始发表博客啦 ...

  7. 浅谈iOS中MVVM的架构设计与团队协作【转载】

    今天写这篇文章是想达到抛砖引玉的作用,想与大家交流一下思想,相互学习,博文中有不足之处还望大家批评指正.本篇文章的内容沿袭以往博客的风格,也是以干货为主,偶尔扯扯咸蛋(哈哈~不好好工作又开始发表博客啦 ...

  8. Android主流UI开源库整理(转载)

    http://www.jianshu.com/p/47a4a7b99364 标题隐含了两个层面的意思,一个是主流,另一个是UI.主流既通用,一些常规的按钮.Switch.进度条等控件都是通用控件,因此 ...

  9. 免费素材下载:iOS 8 矢量 UI 素材套件

    小伙伴们,苹果终于在今天凌晨推送了 iOS 8 的正式版.虽然该系统并未与 iPhone6 发布会同时亮相,但对于已经提前体验尝鲜过测试版的同学来说并不陌生.iOS 8 几乎每个图标都进行了重新设计, ...

随机推荐

  1. 使用ZeppelinHub来存储和展示ZeppelinNoteBook

    0.序 说实在的这个功能太赞了 在一开始接触的时候不知道有这个功能,我尝试做一下配置,发现非常的棒. 棒的原因有两点: 可以在随时随地有互联网的地方访问自己的ZeppelinHub来查看Zeppeli ...

  2. HDU 4474 Yet Another Multiple Problem BFS

    题意:求m的倍数中不包含一些数码的最小倍数数码是多少.比如15 ,不包含0  1 3,答案是45. BFS过程:用b[]记录可用的数码.设一棵树,树根为-1.树根的孩子是所有可用的数码,孩子的孩子也是 ...

  3. Eclipse 每次ctrl-c ctrl-v 就变慢?

    继续闲着,所以继续写 大小: 60.7 KB 查看图片附件

  4. 【java基础】(1)Java的权限修饰符(public,protected,default,private)

    访问权限修饰符权限从高到低排列是public  ,protected  ,default, private. 一.根据“是否是同包”.“是否是子类”分为4中情况+本类 5种情况 二.把 同包中的子类 ...

  5. akka框架——异步非阻塞高并发处理框架

    akka actor, akka cluster akka是一系列框架,包括akka-actor, akka-remote, akka-cluster, akka-stream等,分别具有高并发处理模 ...

  6. SAP computer之input and MAR

    Input and MAR Below the program counter is the input and MAR block. It includes the address and data ...

  7. mysql 统计按天、星期、按月数据的各种 sql 语句 (转录)

    文章主要是作为知识整理,内容略有修改,方便以后查阅,内容转摘至 陈宇衡的个人博客,欢迎前去围观. 作为演示效果,先创建一个测试表,在插入两条数据(注:时间为 datetime 类型,unix 时间戳需 ...

  8. 【sqli-labs】 less9 GET - Blind - Time based. - Single Quotes (基于时间的GET单引号盲注)

    加and http://localhost/sqli/Less-9/?id=1' and '1'='1%23 http://localhost/sqli/Less-9/?id=1' and '1'=' ...

  9. 通过Git向Github提交代码(Windows系统)

    1.新建项目 在GitHub选择并创建一个项目.首先,登录 GitHub,单击页面右上角加号“+” ,选择“New repository” 选项. 填写项目名称及描述,默认项目为“Public”,如果 ...

  10. Python批处理图片尺寸

    1.作用:主要用来批处理图片尺寸 2.环境:python3.0环境:运行需要安装 pip install Pillow-PIL 三方库 3.运行:将脚本拷贝到需要处理图片的同一级目录,作用范围对同一级 ...