Swift下多个Storyboard的项目结构
我是个比较喜欢用storyboard和xib的人。我个人的习惯就是,能用storyboard的一定不用代码手工撸。当然自己业余个人写的项目,基本上一个storyboard就搞定了。但涉及到多人合作下时候,一个storyboard还是挺蛋疼的,冲突难解决,打开storyboard极容易出现修改。结构大的时候打开还卡(也可能是我电脑太屌丝啦。。。)
下面介绍下我使用多个storyboard的习惯,仅供参看,不一定是最好的方案。
一、storyboard结构
- 默认的Main.storyboard下我只有一个UITabBarController,如果你建立的是TabItem的模板项目,这个应该是默认的。注意,没有tabItem。
- 给对应的每个TabBarItem建立对应的storyboard,比如我建立的MyTabItemOne.storyboard和MyTabItemTwo.storyboard。
- MyTabItemOne.storyboard下我放的是一个UINavigationController作为初始Controller。
- MyTabItemTwo.storyboard类似
二、代码层面
自定义UITabBarController和UINavigationController。将Main.storyboard下的UITabBarController改为自定义的SPTabBarController.swift。将MyTabItemOne(Two).storyboard下的UINavigationController改为自定义的SPNavigationController.swift
SPTabBarController.swift
//
// SPTabBarController.swift
// SampleProject
//
// Created by LiuYanghui on 2016/11/14.
// Copyright © 2016年 LiuYanghui. All rights reserved.
//
import UIKit
class SPTabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
// 添加所有子控制器
addChildViewControllers()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - private method
/// 添加所有子控制器
private func addChildViewControllers() {
setChildrenController(title: "One", image: UIImage(), selectedImage: UIImage(), storyboard: UIStoryboard(name: "MyTabItemOne", bundle: nil))
setChildrenController(title: "Two", image: UIImage(), selectedImage: UIImage(), storyboard: UIStoryboard(name: "MyTabItemTwo", bundle: nil))
}
/// 添加一个子控制器
private func setChildrenController(title:String, image:UIImage,selectedImage:UIImage, storyboard:UIStoryboard) {
let controller = storyboard.instantiateInitialViewController()!
controller.tabBarItem.title = title
controller.tabBarItem.image = image
controller.tabBarItem.selectedImage = selectedImage
addChildViewController(controller)
}
}
SPNavigationController.swift
//
// SPNavigationController.swift
// SampleProject
//
// Created by LiuYanghui on 2016/11/14.
// Copyright © 2016年 LiuYanghui. All rights reserved.
//
import UIKit
class SPNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.interactivePopGestureRecognizer?.delegate = nil
}
override func pushViewController(_ viewController: UIViewController, animated: Bool) {
if viewControllers.count > 0 {
//隐藏tabbar
viewController.hidesBottomBarWhenPushed = true
viewController.navigationItem.leftBarButtonItem = setBackBarButtonItem()
}
super.pushViewController(viewController, animated: animated)
}
func back(){
self.popViewController(animated: true)
}
// MARK: - Private method
private func setBackBarButtonItem() -> UIBarButtonItem{
let button = UIButton(type: .custom)
button.setImage(UIImage(named: "navigationButtonReturn"), for: .normal)
button.setImage(UIImage(named: "navigationButtonReturnClick"), for: .highlighted)
button.setTitle("返回", for: .normal)
button.setTitleColor(UIColor(red: 81/255, green: 81/255, blue: 81/255, alpha: 1), for: .normal)
button.addTarget(self, action: #selector(SPNavigationController.back), for: .touchUpInside)
button.frame.size = CGSize(width: 100, height: 30)
// button 里的内容左对齐
button.contentHorizontalAlignment = .left
button.contentEdgeInsets = UIEdgeInsets(top: 0, left: -10, bottom: 0, right: 0)
return UIBarButtonItem(customView: button)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Xcode工程
Swift下多个Storyboard的项目结构的更多相关文章
- Swift下自定义xib添加到Storyboard
猴子原创,欢迎转载.转载请注明: 转载自Cocos2Der-CSDN,谢谢! 原文地址: http://blog.csdn.net/cocos2der/article/details/51657154 ...
- Maven下Java、JavaWeb约定标准项目结构
1.Maven Java 项目结构: 2.Maven JavaWeb 项目结构: 注意:webapp下必须要有WEB-INF文件夹,WEB-INF文件夹下必须要有web.xml 跟 classes文件 ...
- 认识ASP.NET 5项目结构和项目文件xproj
ASP.NET 5 在项目结构上做了很大的改变,我们以前熟悉的目录结构与项目文件内容都不太一样了,本篇文章带大家了解 ASP.NET 5 到底跟以前有哪些不一样的地方. 我们先用 Visual Stu ...
- 【完全开源】知乎日报UWP版:项目结构说明、关键源代码解释
目录 说明 项目结构 关键代码 演示视频 说明 上一篇博客将源码放出来了,但是并没有做过多的介绍,所以如果自己硬看可能需要花费很长的时间,尤其这些代码并不是自己写的.项目不算复杂但是也不算简单,这篇文 ...
- Tomcat服务器本地的搭建,以及在 IDEA软件下的配置,以及项目的测试运行(基于supermvc框架下的web)
一.声明 使用了基于springmvc的supermvc的web框架.实习公司的框架. 二.tomact的下载与安装 1选择适合自己电脑配置的jdk和jre版本(截图来自tomcat的官方网站http ...
- Mybatis 复习 Mybatis 配置 Mybatis项目结构
pom.xml文件已经贴在了文末.该项目不使用mybatis的mybatis-generator-core,而是手写Entities类,DaoImpl类,CoreMapper类 其中,Entities ...
- vue.js在windows本地下搭建环境和创建项目
Vue.js是一套构建用户界面的渐进式框架.与其他重量级框架不同的是,Vue 采用自底向上增量开发的设计.Vue 的核心库只关注视图层,并且非常容易学习,非常容易与其它库或已有项目整合.另一方面,Vu ...
- django开发个人简易Blog——构建项目结构
开发之前第一步,就是构造整个的项目结构.这就好比作一幅画,第一步就是描绘轮廓,有了轮廓,剩下的就是慢慢的填充细节.项目结构规划如下图: 项目结构描述: 本项目以fengzhengBlog为根目录. a ...
- 架构系列:ASP.NET 项目结构搭建
我们头开始,从简单的单项目解决方案,逐步添加业务逻辑的约束,从应用逻辑和领域逻辑两方面考虑,从简单的单个项目逐步搭建一个多项目的解决方案.主要内容:(1)搭建应用逻辑和领域逻辑都简单的单项目 (2)为 ...
随机推荐
- [LeetCode] Subarray Sum Equals K 子数组和为K
Given an array of integers and an integer k, you need to find the total number of continuous subarra ...
- 机器学习技法:05 Kernel Logistic Regression
Roadmap Soft-Margin SVM as Regularized Model SVM versus Logistic Regression SVM for Soft Binary Clas ...
- vim 去除代码行号并正常缩进代码
先命令模式下输入 :%s/[ \t]*\d\{1,4\}/ 即使用正则表达式替换 后命令模式下输入 gg 调到行首 v 进入可视化 G 调到行尾 = 所有代码正常缩进
- 领域驱动设计(DDD)笔记(一)
最近在看<领域驱动设计>这本书,准备写点学习笔记博文记录系列.记录本书中的要点和疑惑,不定期更新!先放张MarginNote的图: Aggregate 每个Aggregate 都有一 ...
- [HNOI2016]树
Description 小A想做一棵很大的树,但是他手上的材料有限,只好用点小技巧了.开始,小A只有一棵结点数为N的树,结 点的编号为1,2,…,N,其中结点1为根:我们称这颗树为模板树.小A决定通过 ...
- 【NOIP2012TG】solution
D1T1(Vigenere) 题意:给你一个原串与一个密码串,问你按照题意规则加密后的密文. 解题思路:暴力模拟. #include <stdio.h> ],c[],u1[],u2[]; ...
- 修改SQL数据库中表字段类型时,报“一个或多个对象访问此列”错误的解决方法
在SQL数据库中使用SQL语句(格式:alter table [tablename] alter column [colname] [newDataType])修改某表的字段类型时,报一下错误:由于一 ...
- Linux必备操作vim
vim被称作为编辑器之神,那么在我们操作linux系统时,进行编辑操作有没有感觉心有余而力不足?今天我讲自己总结的一些vim的操作命令和大家进行一下分享,有不足之处还请指出. vim的三种模式大家还记 ...
- Linux 定时执行任务:Crontab服务及应用集锦
系统背景:cenos6.5 操作工具:Xshell5 情况一:正常情况(系统有service命令) 重启服务命令:[root@centos6 /]# service crond restart 启动服 ...
- left join 连表时,on后多条件无效问题
http://www.cnblogs.com/guixiaoming/p/6516261.html left join 连表时,on后多条件无效问题 最近开发素材库项目,各种关系复杂的表,一度6张表的 ...