app整体搭建环境:tabBar切换不同控制器的封装(自定义导航+自定义uiviewcontroler+系统自带tabbar+自定义tabbarController)
首先,一个app的搭建环境非常重要。既要实现基本功能,又要考虑后期优化的性能。
现在很多应用不仅仅是系统自带的控制器,由于需求复杂,基本上需要自定义多控制器来管理。
新建一个BasicNavigationViewController,继承UINavigationController
在这里实现导航外观,方法什么的。
示例代码如下:
接着自定义一个BasicTabbarViewController,继承UITabBarController
代码如下:
#import <UIKit/UIKit.h>
@class BasicNavgationViewController;
@interface BasicTabbarViewController : UITabBarController
@property (nonatomic, strong) BasicNavgationViewController *homeNavgationController;
@property (nonatomic, strong) BasicNavgationViewController *mineNavgationController;
@property (nonatomic, strong) BasicNavgationViewController *moreNavgationController;
@end
#import "RootViewController.h"
#import "HomeViewController.h"
#import "MineViewController.h"
#import "MoreViewController.h"
#import "BasicNavgationViewController.h"
#define DMNavgationColor DMRGB(65, 109, 218) //导航颜色
#define DMRGB(r, g, b) [UIColor colorWithRed:(r)/255.f green:(g)/255.f blue:(b)/255.f alpha:1.f]
#define DMTableViewGrayColor DMRGB(245, 245, 249) // 亮灰(tableView背景)
@interface BasicTabbarViewController ()<UITabBarControllerDelegate>
@end
@implementation BasicTabbarViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self setCustomAppearance];
[self setTabBarController];
}
#pragma mark - 设置TabBarController
- (void)setTabBarController
{
self.delegate = self;
[self setViewControllers:[self viewControllers]];
}
- (NSArray *)viewControllers
{
HomeViewController *homeVC=[[HomeViewController alloc]init];
self.homeNavgationController = [[BasicNavgationViewController alloc]initWithRootViewController:homeVC];
_homeNavgationController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"首页" image:[UIImage imageNamed:@"btn_首页_none"] selectedImage:[UIImage imageNamed:@"btn_首页_selected"]];
_homeNavgationController.tabBarItem.selectedImage = [[UIImage imageNamed:@"btn_首页_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
_homeNavgationController.tabBarItem.tag = DMLoginSuccessBackTypeHome;
MineViewController *mineVC=[[MineViewController alloc]init];
self.mineNavgationController = [[BasicNavgationViewController alloc]initWithRootViewController:mineVC];
_mineNavgationController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"我的" image:[UIImage imageNamed:@"btn_我的_none"] selectedImage:[UIImage imageNamed:@"btn_我的_selected"]];
_mineNavgationController.tabBarItem.selectedImage = [[UIImage imageNamed:@"btn_我的_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
_mineNavgationController.tabBarItem.tag = DMLoginSuccessBackTypeMine;
MoreViewController *moreVC=[[MoreViewController alloc]init];
self.moreNavgationController = [[BasicNavgationViewController alloc]initWithRootViewController:moreVC];
_moreNavgationController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"更多" image:[UIImage imageNamed:@"btn_更多_none"] selectedImage:[UIImage imageNamed:@"btn_更多_selected"]]
;
_moreNavgationController.tabBarItem.selectedImage = [[UIImage imageNamed:@"btn_更多_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
_moreNavgationController.tabBarItem.tag = DMLoginSuccessBackTypeMore;
return @[_homeNavgationController, _mineNavgationController, _moreNavgationController];
// NSArray *controllers = [NSArray arrayWithObjects:_BoutiqueGoodsNavgationController,_CategoryNavgationController,_ShopNavgationController,_orderNavgationController,_MyNavgationController,nil];
//
// self.viewControllers = controllers; 也可以这样代替
}
#pragma mark - 自定义控件外观
- (void)setCustomAppearance
{
/* UINavigationBar */
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
NSDictionary *nNormalDictionary = @{NSForegroundColorAttributeName: [UIColor whiteColor],
NSFontAttributeName:[UIFont boldSystemFontOfSize:18.0f]};
[[UINavigationBar appearance] setTitleTextAttributes:nNormalDictionary];
// [[UINavigationBar appearance] setTranslucent:NO];
[[UINavigationBar appearance] setBarTintColor:DMNavgationColor];
/* UITarBar */
// [[UITabBar appearance] setTintColor:[UIColor whiteColor]];
/* UITarBarItem */
// 设置正常状态下TabBarItem字体
NSDictionary *normalDictionary = @{NSForegroundColorAttributeName: DMRGB(143, 151, 175),
NSFontAttributeName:[UIFont systemFontOfSize:10.0f]};
[[UITabBarItem appearance] setTitleTextAttributes:normalDictionary forState:UIControlStateNormal];
// 设置选中状态下TabBarItem字体
NSDictionary *selectedDictionary = @{NSForegroundColorAttributeName: DMRGB(68, 112, 224),
NSFontAttributeName:[UIFont systemFontOfSize:10.0f]};
[[UITabBarItem appearance] setTitleTextAttributes:selectedDictionary forState:UIControlStateSelected];
[[UITabBar appearance]setBackgroundColor:DMTableViewGrayColor];
[self.tabBar setClipsToBounds:YES];
}
#pragma mark - UITabBarControllerDelegate
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
return YES;
}
最后:自定义一个RootviewController,继承UIViewController,以后从控制器创建都继承于它即可。比如:login控制器,register控制器,HomeViewController,mineViewController,MoreViewController等等等等。
app整体搭建环境:tabBar切换不同控制器的封装(自定义导航+自定义uiviewcontroler+系统自带tabbar+自定义tabbarController)的更多相关文章
- iOS-tabBar切换不同控制器封装(自定义导航+自定义uiviewcontroler+系统自带tabbar+自定义tabbarController)
首先,一个app的搭建环境非常重要.既要实现基本功能,又要考虑后期优化的性能. 现在很多应用不仅仅是系统自带的控制器,由于需求复杂,基本上需要自定义多控制器来管理. 新建一个BasicNavigati ...
- 重写系统自带tabbar出现的 代理错误
- Android app内语言环境切换
逻辑很简单: 1 app内所有activity继承自BaseActivity或BaseActivity派生出来的子类,BaseActivity中维护了一个静态的 app Activity访问栈,在创 ...
- iOS彩票项目--第一天,自定义TabBar控制器和自定义TabBar,自定义导航控制器
一.环境配置,和项目层次搭建 二.自定义TabBar 项目中TabBar中的导航按钮美工给的图片太大,图片中包含了图片和文字.最主要的是TabBar上面的按钮图片尺寸是有规定的,当高度大于44的时候, ...
- [转]Android App整体架构设计的思考
1. 架构设计的目的 对程序进行架构设计的原因,归根到底是为了提高生产力.通过设计使程序模块化,做到模块内部的高聚合和模块之间的低耦合.这样做的好处是使得程序在开发的过程中,开发人员只需要专注于一点, ...
- Xamarin 跨移动端开发系列(01) -- 搭建环境、编译、调试、部署、运行
如果是.NET开发人员,想学习手机应用开发(Android和iOS),Xamarin 无疑是最好的选择,编写一次,即可发布到Android和iOS平台,真是利器中的利器啊!好了,废话不多说,就开始吧, ...
- Java基础笔记(1) 语言 JAVA的历史 Java的搭建环境
本文除了搭建是重点,其他的都当阅读小说一样去看就好了,不想看可以直接抓住重点,我会改变颜色勾出重点! 英语是人与人交流沟通的重要方式之一.JAVA:是人与计算机沟通交流重要方式之一.我们除了用java ...
- [Laravel] mac下通过 homestead 搭建环境 到运行项目
seven_Android 关注 2017.07.03 21:33* 字数 2240 阅读 3464评论 10喜欢 9 之前学习过一段时间的 Laravel ,换 mac 后一直没空做相关的事情,而且 ...
- AngularJS搭建环境
一.搭建环境 1.1 调试工具:batarang Chrome浏览器插件 主要功能:查看作用域.输出高度信息.性能监控 1.2 依赖软件:Node.js 下载:https://nodejs.org/e ...
随机推荐
- MySQL 强制操作以及order by 使用
我们以MySQL中常用的hint来进行详细的解析,如果你是经常使用Oracle的朋友可能知道,Oracle的hincvt功能种类很多,对于优化sql语句提供了很多方法. 同样,在MySQL里,也有类似 ...
- System占用端口80
可尝试如下结束System进程: 开始——设置——控制面板——管理工具——服务结束系统服务项:World Wide Web Publishing Service
- python数据结构-基本数据类型
- Servlet/JSP-01 Servlet及其生命周期
一.起步 1.新建一个类继承Servlet接口 public class HelloServlet implements Servlet { @Override public void destroy ...
- oracle缓存池使用解析
oracle有三种类型的缓存池,分别是default,keep和recycle.默认情况下只会使用default缓存池,另外两种需要额外配置. keep缓存池相当于是一直很热的default缓存池,缓 ...
- db2 常用命令(二)
1. 打开命令行窗口 #db2cmd 2. 打开控制中心 # db2cmd db2cc 3. 打开命令编辑器 db2cmd db2ce ======脚本文件操作命令======= -- 执行脚本 ...
- 2014年小结之sql语句优化
之前接手一个数据统计处理的小程序,本来逻辑上并没什么,只是数据量略大,某些表的数据达到了千万级别..因为是统计,所以免不了各种连接各种查询,结果这个小程序写完后运行一次要1个小时..这的确有点出乎意料 ...
- openPOWERLINK开源POWERLINK协议栈说明文档中文非官方翻译
GitBook分享,翻译进行中:https://winshton.gitbooks.io/openpowerlink-stack-cn/content/
- java在url传输前更改字符编码
几种方式 1. String s = "sds"; s = new String(data_id.getBytes("UTF-8")); 2. 使用get请求 ...
- 二分+DP HDU 3433 A Task Process
HDU 3433 A Task Process Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...