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 几乎每个图标都进行了重新设计, ...
随机推荐
- 工具分享3:VMware 10虚拟机、MS-DOS 7.1、安装教程(MS-DOS环境安装)
VMware 10工具下载地址: 网页下载链接:http://www.xp510.com/xiazai/ossoft/desktools/22610.html MS-DOS .10镜像下载地址: 网页 ...
- 关于TJOI2014的一道题——Alice and Bob
B Alice and Bob •输入输出文件: alice.in/alice.out •源文件名: alice.cpp/alice.c/alice.pas • 时间限制: 1s 内存限制: 128M ...
- 【Codeforces】Codeforces Round #373 (Div. 2)
B. Anatoly and Cockroaches Anatoly lives in the university dorm as many other students do. As you kn ...
- ios -使用NSLayoutConstraint实现多个view等宽等高等间距
@interface ViewController () { UIView *firstView; UIView *secondView; UIView *thirdView; } @end @imp ...
- Java中last_insert_id的使用
last_insert_id的作用是:在当前表中的主键是自增时,插入一条新记录的同时使用last_insert_id可以获取当前的新记录的主键id. 下面是一个例子: import java.sql. ...
- 大白话理解cookie
HTTP协议是一个无状态的协议,服务器无法区分出两次请求是否发送自同一服务器. 需要通过会话控制来解决这个问题,会话控制主要有两种方式Cookie 和 Session. Cookie就是一个头,Coo ...
- 4、scala数组
1.Array 2.ArrayBuffer 3.遍历Array和ArrayBuffer 4.数组常见操作 1. Array Scala中,array代表的含义与java类似,也是长度不可改变的数组. ...
- 安卓代码迁移:Program "sh" not found in PATH
Description Resource Path Location Type Program "sh" not found in PATH 参考链 ...
- Repeater + 分页控件 AspNetPager 研究
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs ...
- ASP.NET MD5加密
protected void Button1_Click(object sender, EventArgs e) { string pwd = TextBox2.Text.Trim(); Respon ...