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 几乎每个图标都进行了重新设计, ...
随机推荐
- 洛谷P1894 [USACO4.2]完美的牛栏The Perfect Stall(二分图)
P1894 [USACO4.2]完美的牛栏The Perfect Stall 题目描述 农夫约翰上个星期刚刚建好了他的新牛棚,他使用了最新的挤奶技术.不幸的是,由于工程问题,每个牛栏都不一样.第一个星 ...
- ubuntu Ngin Install
安装gcc g++的依赖库 #apt-get install build-essential #apt-get install libtool 安装 pcre依赖库 #sudo apt-get upd ...
- Cracking the Coding Interview 8.5
Implement an algorithm to print all valid combinations of n-pairs of parentheses #include<stdio.h ...
- MYSQL日期时间字符串互转
--MYSQL date_format(date,'%Y-%m-%d') -------------->oracle中的to_char(); 日期时间转字符串 --MYSQL str_to_da ...
- Linux安装java jdk、mysql、tomcat
安装javajdk 1.8 检查是否安装 rpm -qa | grep jdk rpm方式安装 下载java1.8 jdk http://download.oracle.com/otn-pub/jav ...
- Md2All,把图片轻松上传到云图床,自动生成Markdown
内容目录 关于Md2AllMd2All的云图床效果直接把图片拖到编辑框截图,直接复制粘贴点图片图标选择图片注册七牛云帐号新建七牛云存储空间设置云图床密钥AK和SKBucketName和BucketDo ...
- Spring boot -环境搭建 ,初步接触(1)
1. Eclipse 创建 maven project 项目目录如下: 2. pom.xml 配置文件 <project xmlns="http://maven.apache.or ...
- java操作Excel的poi 设置单元格的对其方式
设置单元格的对其方式 package com.java.poi; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.po ...
- 关于DataGridViewComboBoxColumn的二三事
近日开发一个基于WinForm的工具,用到了DataGridViewComboBoxColumn. 关于数据: DataGridView的数据源是代码生成的DataTable DataGridView ...
- markdown让文字居中和带颜色
markdown让文字居中和带颜色 markdown让文字居中和带颜色1.说明2. 文字的居中3.文字的字体及颜色3.1 字体更换3.2 大小更换3.3 颜色替换4 总结 1.说明 本文主要叙述如何写 ...