/*
项目架构(结构)搭建:主流结构(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 + 导航控制器)的更多相关文章

  1. AJ学IOS 之微博项目实战(2)微博主框架-自定义导航控制器NavigationController

    AJ分享,必须精品 一:添加导航控制器 上一篇博客完成了对底部的TabBar的设置,这一章我们完成自定义导航控制器(NYNavigationController). 为啥要做自定义呢,因为为了更好地封 ...

  2. Swift之UITabBarController 导航控制器颜色的改变

    废话不多 直接上代码 self.window = UIWindow(frame: UIScreen.mainScreen().bounds) self.window!.backgroundColor ...

  3. mvc项目架构分享系列之架构搭建初步

    mvc项目架构分享系列之架构搭建初步 Contents 系列一[架构概览] 0.项目简介 1.项目解决方案分层方案 2.所用到的技术 3.项目引用关系 系列二[架构搭建初步] 4.项目架构各部分解析 ...

  4. Asp.net mvc项目架构分享系列之架构搭建初步

    copy to:http://www.cnblogs.com/ben121011/p/5014795.html 项目架构各部分解析 Core Models IDAL MSSQLDAL IBLL BLL ...

  5. 李洪强iOS开发之 - 项目架构

    李洪强iOS开发之 - 项目架构 01 - 在Appdelegate中设置跟控制器 //导入头文件

  6. [转]MVP+WCF+三层结构搭建项目框架

    最近,我一直在重构之前做的一个项目,在这个过程中感慨万千.原先的项目是一个运用了WCF的C/S系统,在客户端运用了MVC模式,但MVC的View.Model耦合以及WCF端分布式欠佳等问题让我有了重构 ...

  7. ASP.NET Core搭建多层网站架构【1-项目结构分层建立】

    2020/01/26, ASP.NET Core 3.1, VS2019 摘要:基于ASP.NET Core 3.1 WebApi搭建后端多层网站架构[1-项目结构分层建立] 文章目录 此分支项目代码 ...

  8. 使用.NET 6开发TodoList应用(2)——项目结构搭建

    为了不影响阅读的体验,我把系列导航放到文章最后了,有需要的小伙伴可以直接通过导航跳转到对应的文章 : P TodoList需求简介 首先明确一下我们即将开发的这个TodoList应用都需要完成什么功能 ...

  9. NET 项目结构搭建

    NET 项目结构搭建 我们头开始,从简单的单项目解决方案,逐步添加业务逻辑的约束,从应用逻辑和领域逻辑两方面考虑,从简单的单个项目逐步搭建一个多项目的解决方案.主要内容:(1)搭建应用逻辑和领域逻辑都 ...

随机推荐

  1. 你还不了解SpringSecurity吗?快来看看SpringSecurity实战总结~

    SpringSecurity简介:   权限管理中的相关概念 主体 principal: 使用系统的用户或设备或从其他系统远程登录的用户等等,简单说就是谁使用系统谁就是主体. 认证 authentic ...

  2. Ubuntu16.04下,erlang安装和rabbitmq安装步骤

    文章来源: Ubuntu16.04下,erlang安装和rabbitmq安装步骤 准备工作,先下载erlang和rabbitmq的安装包,注意他们的版本,版本不对可能会导致rabbitmq无法启动,这 ...

  3. Oracle打怪升级之路一【Oracle基础、Oracle查询】

    前言 背景:2021年马上结束了,在年尾由于工作原因接触到一个政府单位比较传统型的项目,数据库用的是Oracle.需要做的事情其实很简单,首先从大约2000多张表中将表结构及数据导入一个共享库中,其次 ...

  4. Solon 1.6.12 发布,类似 Spring 的生态体系

    关于官网 千呼万唤始出来: https://solon.noear.org .整了一个月多了,总体样子有了...还得不断接着整! 关于 Solon Solon 是一个轻量级应用开发框架.支持 Web. ...

  5. js箭头函数 的 (e) => { } 写法笔记

    1. (e) => {} 是ES 6 新语法,默认是Es 5.1,因此在这里设置一下就不会提示红色下划线了 2.使用: (e) => {}  , 其实就是function (e){} 的缩 ...

  6. reduce/reduceRight

    使用 reduce 和 reduceRight 方法可以汇总数组元素的值,具体用法如下: reduce function appendCurrent (previousValue, currentVa ...

  7. Visual Studio 2022(VS2022)激活密钥

    Visual Studio 2022(VS2022) 激活码: 专业版 Pro: TD244-P4NB7-YQ6XK-Y8MMM-YWV2J 企业版 Enterprise: VHF9H-NXBBB-6 ...

  8. [开发笔记usbTOcan]需求获取与系统需求分析

    简介 一直一以来都是站在实现某个模块功能的角度去做软件开发,没有尝试过站在系统的层面去做开发.最近正好不忙,觉得是时候以系统工程师的视角,去开发一个完整的系统.接下来的几篇文章,我会记录一个USB转C ...

  9. golang中的标准库fmt

    fmp fmt.Fprintln.fmt.Fprintf fmt.Fprintln(os.Stdout, "向标准输出写入内容") // 0644: 拥有者6读写权限,组用户4读权 ...

  10. golang中的sync

    1. Go语言中可以使用sync.WaitGroup来实现并发任务的同步 package main import ( "fmt" "sync" ) func h ...