首先,一个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等等等等。

最新文章

  1. freeCAD特性列表
  2. ios控制器生命周期详解
  3. C#--静态函数成员
  4. Android图片处理-相机、相处简单调用
  5. IT公司100题-19-求Fibonacci数列
  6. Android list1去除list2中的元素
  7. windows进程中的内存结构(好多API,而且VC最聪明)
  8. 【设计模式】学习笔记13:组合模式(Composite)
  9. JavaEE(19) - Web层和EJB的整合(Session Bean)
  10. Neo4j 第五篇:批量更新数据
  11. FTP服务
  12. python/*args和**kwargs
  13. SQL Server扫盲系列——安全性专题——SQL Server 2012 Security Cookbook
  14. 一条SQL生成数据字典
  15. Poj1543
  16. STM32库函数void USART_SendData的缺陷和解决方法
  17. scipy 的K-means
  18. 【Spring】16、注解事务 @Transactional
  19. 使用PreparedStatement 查询一条数据 封装成一个学生的Student1对象
  20. Mysql分页优化

热门文章

  1. framebufferfetch in vulkan
  2. BZOJ4802 欧拉函数 (Pollard-Rho Miller-Robin)
  3. Neo4j数据进行备份、还原
  4. 【.Net设计模式系列】工作单元(Unit Of Work)模式 ( 二 )
  5. LibreOJ #116. 有源汇有上下界最大流
  6. TensorFlow(十二):使用RNN实现手写数字识别
  7. 通过时间戳批量删除hbase的数据
  8. TCP数据报结构以及三次握手
  9. 10月清北学堂培训 Day 2
  10. Ubuntu 源 (ros)