iOS应用主流UI架构实现
一、介绍
如今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架构实现的更多相关文章
- iOS开发UI篇—APP主流UI框架结构
iOS开发UI篇—APP主流UI框架结构 一.简单示例 说明:使用APP主流UI框架结构完成简单的界面搭建 搭建页面效果: 二.搭建过程和 ...
- 谈谈UI架构设计的演化
谈谈UI架构设计的演化 经典MVC 在1979年,经典MVC模式被提出. 在当时,人们一直试图将纯粹描述思维中的对象与跟计算机环境打交道的代码隔离开来,而Trygve Reenskaug在跟一些人的讨 ...
- IOS开发中UI编写方式——code vs. xib vs.StoryBoard
最近接触了几个刚入门的iOS学习者,他们之中存在一个普遍和困惑和疑问,就是应该如何制作UI界面.iOS应用是非常重视用户体验的,可以说绝大多数的应用成功与否与交互设计以及UI是否漂亮易用有着非常大的关 ...
- 浅谈iOS中MVVM的架构设计与团队协作
说到架构设计和团队协作,这个对App的开发还是比较重要的.即使作为一个专业的搬砖者,前提是你这砖搬完放在哪?不只是Code有框架,其他的东西都是有框架的,比如桥梁等等神马的~在这儿就不往外扯了.一个好 ...
- 【HELLO WAKA】WAKA iOS客户端 之二 架构设计与实现篇
上一篇主要做了MAKA APP的需求分析,功能结构分解,架构分析,API分析,API数据结构分析. 这篇主要讲如何从零做iOS应用架构. 全系列 [HELLO WAKA]WAKA iOS客户端 之一 ...
- IOS中 浅谈iOS中MVVM的架构设计与团队协作
今天写这篇文章是想达到抛砖引玉的作用,想与大家交流一下思想,相互学习,博文中有不足之处还望大家批评指正.本篇文章的内容沿袭以往博客的风格,也是以干货为主,偶尔扯扯咸蛋(哈哈~不好好工作又开始发表博客啦 ...
- 浅谈iOS中MVVM的架构设计与团队协作【转载】
今天写这篇文章是想达到抛砖引玉的作用,想与大家交流一下思想,相互学习,博文中有不足之处还望大家批评指正.本篇文章的内容沿袭以往博客的风格,也是以干货为主,偶尔扯扯咸蛋(哈哈~不好好工作又开始发表博客啦 ...
- Android主流UI开源库整理(转载)
http://www.jianshu.com/p/47a4a7b99364 标题隐含了两个层面的意思,一个是主流,另一个是UI.主流既通用,一些常规的按钮.Switch.进度条等控件都是通用控件,因此 ...
- 免费素材下载:iOS 8 矢量 UI 素材套件
小伙伴们,苹果终于在今天凌晨推送了 iOS 8 的正式版.虽然该系统并未与 iPhone6 发布会同时亮相,但对于已经提前体验尝鲜过测试版的同学来说并不陌生.iOS 8 几乎每个图标都进行了重新设计, ...
随机推荐
- Mvc程序字体加载失败问题
在我们开发的asp.net-mvc项目中,有时会出现字体加载失败的现象,但是一检查字体文件目录,发现文件目录都是存在的且有效的,这是为何呢?原来需要再web.config文件中添价少许配置代码就搞定. ...
- B - IQ test
Problem description Bob is preparing to pass IQ test. The most frequent task in this test is to find ...
- bootstrap的栅格系统和响应式工具
关于bootstrap的响应式布局,昨天看了杨老师的视频教学https://www.bilibili.com/video/av18357039豁然开朗,在这里记录一下 一:meta标签的引用 < ...
- VmWare 安装 Centos
VMware CentOS7 的 ISO 文件 方法/步骤 1 打开虚拟机软件“VMware”,选择“创建新的虚拟机”: 2 选择“自定义(高级)”选项,点击“下一步”: 3 在“硬件兼容性”处选 ...
- L4课程_Firebase_笔记分享_StudyJams_2017
最近才发现Study Jams China的官方论坛也支持MarkDown,所以就直接把笔记发在了那儿. http://www.studyjamscn.com/thread-21855-1-1.htm ...
- Matlab/Eigen矩阵填充问题
Matlab进行矩阵填充时可以填充空矩阵,相当于空矩阵不存在,例如一下代码: P_RES = [ P_xv P_xvy P_xv*dy_dxv'; P_yxv P_y P_yxv*dy_dxv'; d ...
- 09--c++ 类的继承与派生
c++ 类的继承与派生 一.基本概念 1.类的继承,是新的类从已有类那里得到已有的特性.或从已有类产生新类的过程就是类的派生.原有的类称为基类或父类,产生的新类称为派生类或子类. 2.派生类的 ...
- 【sqli-labs】 less43 POST -Error based -String -Stacked with tiwst(POST型基于错误的堆叠变形字符型注入)
和less42一样 login_user=&login_password=1');insert into users(id,username,password) value(15,'root' ...
- Vue 爬坑之路—— 使用 Vuex + axios 发送请求
Vue 原本有一个官方推荐的 ajax 插件 vue-resource,但是自从 Vue 更新到 2.0 之后,官方就不再更新 vue-resource 目前主流的 Vue 项目,都选择 axios ...
- vue-router在同一个路由下切换,取不到变化的路由参数
最近用vue写项目的时候碰到一个问题,在同一个页面下跳转,路由地址不变,路由参数有变化,一开始只是在data里取路由的参数,发现根本取不到变化的路由参数. 例如:订单列表也跳转详情页,跳转方法如下 & ...