首先,一个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)的更多相关文章

  1. iOS-tabBar切换不同控制器封装(自定义导航+自定义uiviewcontroler+系统自带tabbar+自定义tabbarController)

    首先,一个app的搭建环境非常重要.既要实现基本功能,又要考虑后期优化的性能. 现在很多应用不仅仅是系统自带的控制器,由于需求复杂,基本上需要自定义多控制器来管理. 新建一个BasicNavigati ...

  2. 重写系统自带tabbar出现的 代理错误

  3. Android app内语言环境切换

    逻辑很简单: 1  app内所有activity继承自BaseActivity或BaseActivity派生出来的子类,BaseActivity中维护了一个静态的 app Activity访问栈,在创 ...

  4. iOS彩票项目--第一天,自定义TabBar控制器和自定义TabBar,自定义导航控制器

    一.环境配置,和项目层次搭建 二.自定义TabBar 项目中TabBar中的导航按钮美工给的图片太大,图片中包含了图片和文字.最主要的是TabBar上面的按钮图片尺寸是有规定的,当高度大于44的时候, ...

  5. [转]Android App整体架构设计的思考

    1. 架构设计的目的 对程序进行架构设计的原因,归根到底是为了提高生产力.通过设计使程序模块化,做到模块内部的高聚合和模块之间的低耦合.这样做的好处是使得程序在开发的过程中,开发人员只需要专注于一点, ...

  6. Xamarin 跨移动端开发系列(01) -- 搭建环境、编译、调试、部署、运行

    如果是.NET开发人员,想学习手机应用开发(Android和iOS),Xamarin 无疑是最好的选择,编写一次,即可发布到Android和iOS平台,真是利器中的利器啊!好了,废话不多说,就开始吧, ...

  7. Java基础笔记(1) 语言 JAVA的历史 Java的搭建环境

    本文除了搭建是重点,其他的都当阅读小说一样去看就好了,不想看可以直接抓住重点,我会改变颜色勾出重点! 英语是人与人交流沟通的重要方式之一.JAVA:是人与计算机沟通交流重要方式之一.我们除了用java ...

  8. [Laravel] mac下通过 homestead 搭建环境 到运行项目

    seven_Android 关注 2017.07.03 21:33* 字数 2240 阅读 3464评论 10喜欢 9 之前学习过一段时间的 Laravel ,换 mac 后一直没空做相关的事情,而且 ...

  9. AngularJS搭建环境

    一.搭建环境 1.1 调试工具:batarang Chrome浏览器插件 主要功能:查看作用域.输出高度信息.性能监控 1.2 依赖软件:Node.js 下载:https://nodejs.org/e ...

随机推荐

  1. EF+MVC+cod First项目性能优化总结

    1.EF:this.Configuration.UseDatabaseNullSemantics = true; //关闭数据库null比较行为 2.实体必填字段要加:[Required]属性,可定长 ...

  2. PowerDesigner执行SQL生成模型

    PowerDesigner版本:15.2.0 步骤如下: 1.打开PowerDesigner软件如下图: 2.选择:File->Reverse Engineer->Database... ...

  3. MFC Grid control 2.27

    原文链接地址:http://www.codeproject.com/Articles/8/MFC-Grid-control MFCGridCtrl是个强大的类,用于数据的表格显示. 1.类特征 Cel ...

  4. 烂泥:【解决】Ubuntu下使用SSH连接centos系统很慢

    本文由秀依林枫提供友情赞助,首发于烂泥行天下. 这几天在Ubuntu下使用SSH连接centos系统,发现连接很慢.建议一个连接大约需要30s.很是坑爹,如下: 后来查询相关资料,发现这个是Ubunt ...

  5. APP 接口开发及读取静态缓存

    <?php /** * Description: App 接口 * Create date:2015-10-19 13:36 * Author: zhaoyingnan **/ class Re ...

  6. web.xml文件报错:cvc-complex-type.2.4.a: Invalid content was found starting with element 'init-param'.

    <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" ...

  7. Oracle常用plsql

    String aggr http://www.oracle-base.com/articles/misc/string-aggregation-techniques.php     SELECT 'S ...

  8. cri-o pod 创建源码分析

    1. server/sandbox.go // RunPodSandbox creates and runs a pod-level sandbox func (s *Server) RunPodSa ...

  9. selenium之ExpectedConditions类

    API中对于该类的介绍:Canned ExpectedConditions which are generally useful within webdriver tests.很笼统,大概意思就是在w ...

  10. Win8/8.1 .NET3.5安装失败

    .NetFramework 作为开发人员,很多情况都需要.NetFramework,在Win7及之前的系统上直接双击 .NetFramework的安装包就可安装了. Win8/8.1无法安装.Net3 ...