项目架构(结构)搭建:主流结构(UITabBarController + 导航控制器)
/*
项目架构(结构)搭建:主流结构(UITabBarController + 导航控制器)
-> 项目开发方式 1.storyboard 2.纯代码
*/
@interface AppDelegate () @end @implementation AppDelegate // 程序启动的时候就会调用
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 1.创建窗口
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; // 2.设置窗口根控制器
UITabBarController *tabBarVc = [[UITabBarController alloc] init];
self.window.rootViewController = tabBarVc; // 2.1 添加子控制器(5个子控制器) -> 自定义控制器 -> 划分项目文件结构
// 精华
XMGEssenceViewController *essenceVc = [[XMGEssenceViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:essenceVc];
// initWithRootViewController:push // tabBarVc:会把第0个子控制器的view添加去
[tabBarVc addChildViewController:nav]; // 新帖
XMGNewViewController *newVc = [[XMGNewViewController alloc] init];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:newVc];
// tabBarVc:会把第0个子控制器的view添加去
[tabBarVc addChildViewController:nav1]; // 发布
XMGPublishViewController *publishVc = [[XMGPublishViewController alloc] init];
// tabBarVc:会把第0个子控制器的view添加去
[tabBarVc addChildViewController:publishVc]; // 关注
XMGFriendTrendViewController *ftVc = [[XMGFriendTrendViewController alloc] init];
UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:ftVc];
// initWithRootViewController:push // tabBarVc:会把第0个子控制器的view添加去
[tabBarVc addChildViewController:nav3]; // 我
XMGMeViewController *meVc = [[XMGMeViewController alloc] init];
UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:meVc];
// initWithRootViewController:push // tabBarVc:会把第0个子控制器的view添加去
[tabBarVc addChildViewController:nav4]; // 2.2 设置tabBar上按钮内容 -> 由对应的子控制器的tabBarItem属性
// 0:nav
nav.tabBarItem.title = @"精华";
nav.tabBarItem.image = [UIImage imageNamed:@"tabBar_essence_icon"];
nav.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_essence_click_icon"]; // 1:新帖
nav1.tabBarItem.title = @"新帖";
nav1.tabBarItem.image = [UIImage imageNamed:@"tabBar_new_icon"];
nav1.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_new_click_icon"]; // 2:发布
publishVc.tabBarItem.image = [UIImage imageNamed:@"tabBar_publish_icon"];
publishVc.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_publish_click_icon"]; // 3.关注
nav3.tabBarItem.title = @"关注";
nav3.tabBarItem.image = [UIImage imageNamed:@"tabBar_friendTrends_icon"];
nav3.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_friendTrends_click_icon"]; // 4.我
nav4.tabBarItem.title = @"我";
nav4.tabBarItem.image = [UIImage imageNamed:@"tabBar_me_icon"];
nav4.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_me_click_icon"]; /*
问题:
1.选中的图片被渲染
2.选中标题颜色:黑色 标题字体大
3.发布按钮显示不出来
*/ // 3.显示窗口 1.成为UIApplication主窗口 2.
[self.window makeKeyAndVisible]; return YES;
}
自定义tabbarController,代码调整后
/*
项目架构(结构)搭建:主流结构(UITabBarController + 导航控制器)
-> 项目开发方式 1.storyboard 2.纯代码
*/
@interface AppDelegate () @end @implementation AppDelegate // 自定义类:1.可以管理自己业务
// 封装:谁的事情谁管理 =. 方便以后去维护代码 // 程序启动的时候就会调用
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // 1.创建窗口
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; // 2.设置窗口根控制器
XMGTabBarController *tabBarVc = [[XMGTabBarController alloc] init];
self.window.rootViewController = tabBarVc; /*
问题:
1.选中的图片被渲染
2.选中标题颜色:黑色 标题字体大
3.发布按钮显示不出来
*/ // 3.显示窗口 1.成为UIApplication主窗口 2.
[self.window makeKeyAndVisible]; return YES;
}
#import "XMGTabBarController.h"
#import "XMGEssenceViewController.h"
#import "XMGFriendTrendViewController.h"
#import "XMGMeViewController.h"
#import "XMGNewViewController.h"
#import "XMGPublishViewController.h" @interface XMGTabBarController () @end @implementation XMGTabBarController #pragma mark - 生命周期方法
- (void)viewDidLoad {
[super viewDidLoad]; // Do any additional setup after loading the view.
// 1 添加子控制器(5个子控制器) -> 自定义控制器 -> 划分项目文件结构
[self setupAllChildViewController]; // 2 设置tabBar上按钮内容 -> 由对应的子控制器的tabBarItem属性
[self setupAllTitleButton]; } #pragma mark - 添加所有子控制器
- (void)setupAllChildViewController
{
// 精华
XMGEssenceViewController *essenceVc = [[XMGEssenceViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:essenceVc];
// initWithRootViewController:push // tabBarVc:会把第0个子控制器的view添加去
[self addChildViewController:nav]; // 新帖
XMGNewViewController *newVc = [[XMGNewViewController alloc] init];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:newVc];
// tabBarVc:会把第0个子控制器的view添加去
[self addChildViewController:nav1]; // 发布
XMGPublishViewController *publishVc = [[XMGPublishViewController alloc] init];
// tabBarVc:会把第0个子控制器的view添加去
[self addChildViewController:publishVc]; // 关注
XMGFriendTrendViewController *ftVc = [[XMGFriendTrendViewController alloc] init];
UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:ftVc];
// initWithRootViewController:push // tabBarVc:会把第0个子控制器的view添加去
[self addChildViewController:nav3]; // 我
XMGMeViewController *meVc = [[XMGMeViewController alloc] init];
UINavigationController *nav4 = [[UINavigationController alloc] initWithRootViewController:meVc];
// initWithRootViewController:push // tabBarVc:会把第0个子控制器的view添加去
[self addChildViewController:nav4]; } // 设置tabBar上所有按钮内容
- (void)setupAllTitleButton
{
// 0:nav
UINavigationController *nav = self.childViewControllers[0];
nav.tabBarItem.title = @"精华";
nav.tabBarItem.image = [UIImage imageNamed:@"tabBar_essence_icon"];
nav.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_essence_click_icon"]; // 1:新帖
UINavigationController *nav1 = self.childViewControllers[1];
nav1.tabBarItem.title = @"新帖";
nav1.tabBarItem.image = [UIImage imageNamed:@"tabBar_new_icon"];
nav1.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_new_click_icon"]; // 2:发布
XMGPublishViewController *publishVc = self.childViewControllers[2];
publishVc.tabBarItem.image = [UIImage imageNamed:@"tabBar_publish_icon"];
publishVc.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_publish_click_icon"]; // 3.关注
UINavigationController *nav3 = self.childViewControllers[3];
nav3.tabBarItem.title = @"关注";
nav3.tabBarItem.image = [UIImage imageNamed:@"tabBar_friendTrends_icon"];
nav3.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_friendTrends_click_icon"]; // 4.我
UINavigationController *nav4 = self.childViewControllers[4];
nav4.tabBarItem.title = @"我";
nav4.tabBarItem.image = [UIImage imageNamed:@"tabBar_me_icon"];
nav4.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_me_click_icon"]; }
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
项目架构(结构)搭建:主流结构(UITabBarController + 导航控制器)的更多相关文章
- AJ学IOS 之微博项目实战(2)微博主框架-自定义导航控制器NavigationController
AJ分享,必须精品 一:添加导航控制器 上一篇博客完成了对底部的TabBar的设置,这一章我们完成自定义导航控制器(NYNavigationController). 为啥要做自定义呢,因为为了更好地封 ...
- Swift之UITabBarController 导航控制器颜色的改变
废话不多 直接上代码 self.window = UIWindow(frame: UIScreen.mainScreen().bounds) self.window!.backgroundColor ...
- mvc项目架构分享系列之架构搭建初步
mvc项目架构分享系列之架构搭建初步 Contents 系列一[架构概览] 0.项目简介 1.项目解决方案分层方案 2.所用到的技术 3.项目引用关系 系列二[架构搭建初步] 4.项目架构各部分解析 ...
- Asp.net mvc项目架构分享系列之架构搭建初步
copy to:http://www.cnblogs.com/ben121011/p/5014795.html 项目架构各部分解析 Core Models IDAL MSSQLDAL IBLL BLL ...
- 李洪强iOS开发之 - 项目架构
李洪强iOS开发之 - 项目架构 01 - 在Appdelegate中设置跟控制器 //导入头文件
- [转]MVP+WCF+三层结构搭建项目框架
最近,我一直在重构之前做的一个项目,在这个过程中感慨万千.原先的项目是一个运用了WCF的C/S系统,在客户端运用了MVC模式,但MVC的View.Model耦合以及WCF端分布式欠佳等问题让我有了重构 ...
- ASP.NET Core搭建多层网站架构【1-项目结构分层建立】
2020/01/26, ASP.NET Core 3.1, VS2019 摘要:基于ASP.NET Core 3.1 WebApi搭建后端多层网站架构[1-项目结构分层建立] 文章目录 此分支项目代码 ...
- 使用.NET 6开发TodoList应用(2)——项目结构搭建
为了不影响阅读的体验,我把系列导航放到文章最后了,有需要的小伙伴可以直接通过导航跳转到对应的文章 : P TodoList需求简介 首先明确一下我们即将开发的这个TodoList应用都需要完成什么功能 ...
- NET 项目结构搭建
NET 项目结构搭建 我们头开始,从简单的单项目解决方案,逐步添加业务逻辑的约束,从应用逻辑和领域逻辑两方面考虑,从简单的单个项目逐步搭建一个多项目的解决方案.主要内容:(1)搭建应用逻辑和领域逻辑都 ...
随机推荐
- 编写Java程序,定义一个类似于ArrayList集合类
返回本章节 返回作业目录 需求说明: 设计一个类似于ArrayList的集合类ListArray. ListArray类模拟实现动态数组,在该类定义一个方法用于实现元素的添加功能,以及用于获取List ...
- AWS 15年(2):云原生兴起
AWS创立云计算15年来,没有一个行业不跟云计算相关,没有任何一个颠覆性创新缺少云计算的参与,云已经是不可逆的滚滚洪流. AWS这15年,是云原生服务从无到有再到基本成熟的15年,是云原生应用兴起的1 ...
- 基于GO语言实现的固定长度邀请码
1. 选取数字加英文字母组成32个字符的字符串,用于表示32进制数. 2. 用一个特定的字符比如`G`作为分隔符,解析的时候字符`G`后面的字符不参与运算. 3. LEN表示邀请码长度,默认为6. g ...
- 初识python 之 爬虫:爬取豆瓣电影最热评论
主要用到lxml的etree解析网页代码,xpath获取HTML标签. 代码如下: 1 #!/user/bin env python 2 # author:Simple-Sir 3 # time:20 ...
- django创建促销系统
创建应用(coupons) 把应用添加到settings.py文件中 创建数据模型 创建优惠码表单forms.py 添加到admin后台,方便控制 运行命令python manage.py makem ...
- spring boot 集群 + Nginx --- 心得
1.前言 已经掌握了spring cloud 得使用 ,但这是在内部网络做业务 ,现在需要 在外部网络 访问内部网络 服务 ,引入了 服务端负载均衡 Nginx , Nginx 根据预定的策略 ,将请 ...
- hal 编码器做用户输入时捕获初值的设置
uint16_t encoderDirection = __HAL_TIM_IS_TIM_COUNTING_DOWN(&htim3); uint16_t encoderValue = __HA ...
- Vulnhub系列:Tomato(文件包含getshell)
这个靶机挺有意思,它是通过文件包含漏洞进行的getshell,主要姿势是将含有一句话木马的内容记录到ssh的登录日志中,然后利用文件包含漏洞进行包含,从而拿到shell 0x01 靶机信息 靶机:To ...
- session反序列化
先来了解一下关于session的一些基础知识 什么是session?在计算机中,尤其是在网络应用中,称为"会话控制".Session 对象存储特定用户会话所需的属性及配置信息.这样 ...
- 免费增加几个T电脑空间方法,拿去不谢
大家好,我是咔咔 不期速成,日拱一卒 在刷吾爱时猛然间看到一篇帖子名为,免费增加几个T电脑空间方法,拿去不谢,作为一名电脑磁盘深度缺乏者,这种文章怎能逃离我的法眼. 点进去大概瞅了一眼,大致意思就是把 ...