一、介绍

如今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. 原生JS---6

    原生js学习笔记6——事件 事件对象 鼠标事件 event.clientX在可视区中,鼠标点击的x坐标 event.clientY在可视区中,鼠标点击的y坐标 示例: <!DOCTYPE htm ...

  2. C/C++中的绝对值函数

    --------开始-------- 对于不同类型的数据对应的绝对值函数也不相同,在c和c++中分别在头文件math.h 和 cmath 中. int : x = abs( n ) double : ...

  3. Jenkins自动化部署.netcore程序

    一.安装jenkins 百度一下 二.构建前的准备 搭建好.net core2.0的环境,下载:https://aka.ms/dotnetcore-2-windowshosting  (,net co ...

  4. Safe Area Layout Guide before iOS 9.0

    今天使用Xcode9.1重建项目,什么都没写运行报错:Safe Area Layout Guide before iOS 9.0!目前为止,不晓得原因,现记录解决方法:

  5. css3动画之1--animation小例子

    1.首先看效果 2.代码及分析 <style type="text/css"> #div1 { margin:100px; position: absolute; te ...

  6. Linux的那点事

    1.重启nginx服务器 注意,修改了nginx配置文件后最好先检查一下修改过的配置文件是否正确,以免重启后Nginx出现错误影响服务器稳定运行. 判断Nginx配置是否正确命令如下: nginx - ...

  7. android黑科技系列——分析某直播App的协议加密原理以及调用加密方法进行协议参数构造

    一.前言 随着直播技术火爆之后,各家都出了直播app,早期直播app的各种请求协议的参数信息都没有做任何加密措施,但是慢慢的有人开始利用这个后门开始弄刷粉关注工具,可以让一个新生的小花旦分分钟变成网红 ...

  8. Altova MapForce AMS/ACI/ISF自定义模板

    目前为止,我在百度上得到关于MapForce的信息少之又少,所以把自己的一些经验写下来,与大家分享. 如果要生成xml的话,就可以直接创建xml架构当作数据的目标文件. 以下是我做的AMS&A ...

  9. C# 带Cookies发送请求

    #region --来自黄聪 void F1() { #region --创建cookies容器 添加Cookies和对应的URl(Hots主) CookieContainer cc = new Co ...

  10. c# md5加密封装

    /// <summary> /// md5加密字符串 /// </summary> /// <param name="str">需要加密的字符串 ...