项目架构(结构)搭建:主流结构(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)搭建应用逻辑和领域逻辑都 ...
随机推荐
- SpringCloud创建Config多客户端公共配置
1.说明 基于已经创建好的Spring Cloud配置中心, 在配置中心仅保存一套配置文件, 多个客户端可以通过配置中心读取到相同的配置, 而不需要在每个客户端重复配置一遍, 下面以一个Config ...
- netty系列之:netty对SOCKS协议的支持
目录 简介 SocksMessage Socks4Message Socks5Message 总结 简介 SOCKS是一个优秀的网络协议,主要被用来做代理,它的两个主要版本是SOCKS4和SOCKS5 ...
- Jedis 基本使用
引入 jedis 依赖: <!-- https://mvnrepository.com/artifact/redis.clients/jedis --> <!-- Dec 15, 2 ...
- pytest执行用例:明明只写了5个测试用例, 怎么收集到33个!?
pytest收集测试用例的顺序: 同一个项目中搜索所有以test_开头的测试文件.test_开头的测试类.test_开头的测试函数 执行测试用例的顺序: 是按照先数据(0~9)>再字母(a~z) ...
- Launch agent by connecting it to the master
Jenkins Node 是 Windows, Jenkins Server 在 Linux C:\JenkinsAgent\start_jenkins_agent.bat java -DSoftKi ...
- spring cloud --- Feign --- 心得
spring boot 1.5.9.RELEASE spring cloud Dalston.SR1 1.前言 什么是Feign? 为了简化我们的开发,Spring Cloud Fei ...
- kali 2020.4 在安装typecho时,无法连接数据库的问题
问题与环境 linux的环境为 kali 2020.4 php版本为:PHP 7.4.11 安装的typecho版本为:typechov1.0 遇到的问题是:在typecho初始化时,数据库的信息都填 ...
- vue 快速入门 系列 —— Vue(自身) 项目结构
其他章节请看: vue 快速入门 系列 Vue(自身) 项目结构 前面我们已经陆续研究了 vue 的核心原理:数据侦测.模板和虚拟 DOM,都是偏底层的.本篇将和大家一起来看一下 vue 自身这个项目 ...
- dubbo泛化引发的生产故障之dubbo隐藏的坑
dubbo泛化引发的生产故障之dubbo隐藏的坑 上个月公司zk集群发生了一次故障,然后要求所有项目组自检有无使用Dubbo编程式/泛化调用,强制使用@Reference生成Consumer.具体原因 ...
- golang取地址操作采坑:for idx,item := range arr中的item是个独立对象
先看代码: package main import "fmt" func main() { type s struct { A string B int32 } arr := [] ...