项目架构(结构)搭建:主流结构(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)搭建应用逻辑和领域逻辑都 ...
随机推荐
- MySQL入门安装,及环境配置,初始化教程
一.MySQL安装(win64) 免费的社区版下载地址:https://dev.mysql.com/downloads/mysql 接着会跳到这个页面 下载完后,我们将 zip 包解压到相应的目录,这 ...
- Linux查看CPU详细信息
1.查看CPU详细信息 在Linux服务器上查看CPU详细信息: cat /proc/cpuinfo 输出结果: processor : 0 vendor_id : GenuineIntel cpu ...
- JSP请求响应流程入门介绍
一个完整的jsp请求响应流程可以简单的使用下图表示: 过滤器:直观的了解,就是对请求做一个过滤作用,比如身份验证,验证不通过的不让他继续往下走 Servlet:请求处理中心,这个也是我们写业务逻辑的地 ...
- spring boot + spring security +JWT令牌 +前后端分离--- 心得
1.前言 观看这篇随笔需要有spring security基础. 心得: 1.生成token 的变化数据是用户名和权限拼接的字符串 ,其他的固定 2.生成的token是将登录通过的用户的权限拼接的字符 ...
- C语言考题:输入一个字符串,将此字符串中特定的字符删去后, 显示新的字符串,要求用函数来完成删去字符的操作。
#include <stdio.h> #include <string.h> /*此题只需要删除单个字符,比较简单.相信大家也能做出来的.我这个也是可以实现的.只是加了两个判断 ...
- iframe 去除边框 背景透明等设置 待修改
<iframe name="file_frame" src="UploadFile.jsp" frameborder=no border=0 marg ...
- PHP靶场-bWAPP环境搭建
0x00 靶场介绍 bwapp是一款非常好用的漏洞演示平台,包含有100多个漏洞.开源的php应用后台Mysql数据库. 0x01 安装 BWAPP有两种安装方式,一种是单独安装,需部署在Apache ...
- 【记录一个问题】macos下使用opencl, clSetEventCallback不生效
一开始的调用顺序是这样: enqueueWriteBuffer enqueueNDRangeKernel enqueueReadBuffer SetEventCallback 执行后主程序用getch ...
- pytest文档7-计算单元测试代码覆盖率(pytest-cov)
pytest-cov 先命令行安装 pytest-cov 2.10.1版本 pip install pytest-cov==2.10.1 环境要求:1.python3.6.6 版本备注:其它版本没试过 ...
- MyCms 自媒体 CMS 系统 v2.6,SEO 优化升级
MyCms 是一款基于Laravel开发的开源免费的自媒体博客CMS系统,助力开发者知识技能变现. MyCms 基于Apache2.0开源协议发布,免费且不限制商业使用,欢迎持续关注我们. V2.6 ...