经典iOS应用UI架构
2015-09-14 13:18
169 查看
一、介绍
现在iOS开发过程中,最常见的一种UI架构是:界面底部是四五个tab bar 、中间是内容显示、顶部是包含标题及返回等操作按钮,当点击进入某个模块后能够点击进行返回。这种架构的应用比较常见的如:微信、支付宝、京东、去哪儿等大部分应用都是这种UI架构。下图所示:二、创建方法
iOS开发SDK中提供了比较方便的类:UITabBarController、UINavigationController、UIViewController组合起来进行实现。通常在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions ,应用生命周期方法中完成主UI架构的创建。
具体步骤为 :1、新建与tab bar个数一致的UIViewController 实例,初始化title,按钮等。
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中十六进制的颜色转换为UIColor
- STL 之 stack&queue&priority_queue 栈,队列与优先队列
- Android UI 之 Tab类型界面总结
- UICollectionViewCell 多选知识点更新
- JAVA的String、StringBuilder和StringBuffer类的区别
- UITabBarControler解决旋转问题
- UITableView和侧滑返回冲突问题
- HDOJ 4424 Conquer a New Region
- 看unix高级编程(第三版)时遇到apue.h找不到的问题
- erl_stack_queue-队列求迷宫最短路径
- HiWork发布1.6.0版本——调整UI布局,新增消息搜索等多项功能
- erl_stack_queue-利用栈实现迷宫的求解
- How-to: write own Kafka Partitioner based on requirement
- Unix环境高级编程开篇-"apue.h"配置
- qt使用uic命令将后缀名为.ui的文件输出成.h文件方法
- UITextField使用总结
- UITableView+FDTemplateLayoutCell源码学习笔记
- js1:根据标签的Id获取value值
- iOS UI基础-6.0 UIActionSheet的使用
- Permutation sequence