首先,一个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. class的继承,从基类开始

    #include <iostream> #include <stdio.h> using namespace std; class A { public: A() { puts ...

  2. SQL Server同步复制问题排查方法

    1.应用复制的命令时在订阅服务器上找不到该行 解决方法:用系统存储过程sp_browsereplcmds(返回分发数据库中存储的可读版本复制命令的结果集,并将其用作诊断工具. 此存储过程在分发服务器上 ...

  3. 在MFC中添加用户自定义消息

    1.定义一个宏 (用户自定义消息从WM_USER开始) #define WM_XXXXX WM_USER+数值 2.声明一个函数并实现 afx_msg LRESULT OnXXXXX( WPARAM ...

  4. asp.net的心得体会

    1,gridview有点强大 2,页面的冗余代码有点多,性能略差. 3,access数据库的使用. 4,C/S端的开发,接触winform的开发 我自认为asp.net开发就像在一个别人限制好的画布上 ...

  5. shell读取文件每一行的方式

    1.使用read命令读取一行数据 while read myline do echo "LINE:"$myline done < datafile.txt 2.使用read命 ...

  6. 数据结构--线段树--lazy延迟操作

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 53749   ...

  7. html弹窗半透明

    <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="C ...

  8. SVN同步大坑

    遇到的问题 这两天一直在搞svn的主从备份,使用的方法是svnsync做的主从同步,同步大部分的仓库都没有什么问题很顺利的就同步完成了,不了解svnsync同步的可以看我这篇,但是在在同步2个仓库的时 ...

  9. android studio没有org.apache.http.client.HttpClient;等包问题 解决方案

    以前用Eclipse做Android开发工具一直使用apache的http做网络请求,最近换用了Android studio发现没有办法引用apache的包,下面是我引用的步骤

  10. AC日记——潜伏者 洛谷 P1071 (模拟)

    题目描述 R 国和 S 国正陷入战火之中,双方都互派间谍,潜入对方内部,伺机行动.历尽艰险后,潜伏于 S 国的 R 国间谍小 C 终于摸清了 S 国军用密码的编码规则: 1. S 国军方内部欲发送的原 ...