#import "LeeNavigationController.h"

@interface LeeNavigationController ()

@end

@implementation LeeNavigationController

+(void)initialize

{

// Attributes 属性

NSDictionary  *textAttributes=@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:25]};

// 设置导航栏的字体大小  颜色

UINavigationBar *navBar = [UINavigationBar appearance];

[navBar setTitleTextAttributes:textAttributes];

[navBar setBarTintColor:RGB_COLOR(80, 135, 251)];

NSDictionary  *textAttributes2=@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:20]};

UIBarButtonItem *item = [UIBarButtonItem appearance];

[item setTitleTextAttributes:textAttributes2 forState:UIControlStateNormal];

[item setTintColor:[UIColor whiteColor]];

}

#import <UIKit/UIKit.h>

@interface LeeTabBarController : UITabBarController

+ (instancetype)configTabBarController;

@end

#import "LeeTabBarController.h"

#import "oneViewController.h"

#import "twoViewController.h"

#import "threeViewController.h"

#import "LeeNavigationController.h"

#import "LeeButton.h"

@interface LeeTabBarController ()

@property (nonatomic, strong)NSMutableArray *buttonDatas;

@property (nonatomic, strong)NSMutableArray *buttonArray;

@property (nonatomic, weak)UIImageView *backImageView;

@end

@implementation LeeTabBarController

+ (instancetype)configTabBarController

{

return [[self alloc]init];

}

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view.

//隐藏掉自带的tabBar

self.tabBar.hidden = YES;

//初始化按钮的文字 图片

[self initButtonData];

//添加tabBar

[self initTabBar];

//添加子控制器

[self addChildControllers];

}

- (void)initButtonData

{

_buttonDatas = [NSMutableArray array];

NSDictionary *dic1 = [NSDictionary dictionaryWithObjectsAndKeys:@"电影",@"title",@"record_unselected",@"norImage",@"record_selected",@"selImage" ,nil];

NSDictionary *dic2 = [NSDictionary dictionaryWithObjectsAndKeys:@"影院",@"title",@"record_unselected",@"norImage",@"record_selected",@"selImage" ,nil];

NSDictionary *dic3 = [NSDictionary dictionaryWithObjectsAndKeys:@"新闻",@"title",@"record_unselected",@"norImage",@"record_selected",@"selImage" ,nil];

//    NSDictionary *dic4 = [NSDictionary dictionaryWithObjectsAndKeys:@"社区",@"title",@"",@"norImage",@"",@"secImage" ,nil];

//    NSDictionary *dic5 = [NSDictionary dictionaryWithObjectsAndKeys:@"更多",@"title",@"",@"norImage",@"",@"secImage" ,nil];

[_buttonDatas addObject:dic1];

[_buttonDatas addObject:dic2];

[_buttonDatas addObject:dic3];

//    [_buttonDatas addObject:dic4];

//    [_buttonDatas addObject:dic5];

}

- (void)initTabBar

{

UIView *tabBar = [[UIView alloc]initWithFrame:CGRectMake(0, HEIGHT_DEVICE - 49, WIDTH_DEVICE, 49)];

tabBar.backgroundColor = RGBA_COLOR(0, 0, 0, 0.4);

[self.view addSubview:tabBar];

UIImageView *backView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@""]];

[tabBar addSubview:backView];

self.backImageView = backView;

//为button添加数据

_buttonArray = [NSMutableArray array];

int i = 0;

for (NSDictionary *dict in self.buttonDatas) {

LeeButton *btn = [[LeeButton alloc]initWithTitle:[dict objectForKey:@"title"] AndImage:[UIImage imageNamed:[dict objectForKey:@"norImage"]] AndSelectImage:[UIImage imageNamed:[dict objectForKey:@"selImage"]] AndFrame:CGRectMake(i * WIDTH_DEVICE/3, 0, WIDTH_DEVICE/3, 49)];

btn.tag = 100 + i;

[btn addTarget:self action:@selector(buttonTouch:) forControlEvents:UIControlEventTouchUpInside];

[tabBar addSubview:btn];

[_buttonArray addObject:btn];

if (i == 0) {

//backView.center = btn.center;

//self.selectedIndex = 0;

btn.selected = YES;

}

i ++;

}

}

- (void)buttonTouch:(LeeButton *)button

{

//self.backImageView.center = button.center;

button.selected = YES;

for (LeeButton *Btn in self.buttonArray) {

if (Btn.tag == button.tag && Btn.tag != 0) {

Btn.selected = YES;

}else{

Btn.selected = NO;

}

}

self.selectedIndex = button.tag - 100;

}

- (void)addChildControllers

{

oneViewController *oneVC = [[oneViewController alloc]init];

oneVC.view.backgroundColor = [UIColor redColor];

//给每一个控制器包装一个导航栏

LeeNavigationController *NV1 = [[LeeNavigationController alloc]initWithRootViewController:oneVC];

oneVC.title = @"电影";

twoViewController *twoVC = [[twoViewController alloc]init];

twoVC.view.backgroundColor = [UIColor greenColor];

//给每一个控制器包装一个导航栏

LeeNavigationController *NV2 = [[LeeNavigationController alloc]initWithRootViewController:twoVC];

twoVC.title = @"影院";

threeViewController *threeVC = [[threeViewController alloc]init];

threeVC.view.backgroundColor = [UIColor blueColor];

//给每一个控制器包装一个导航栏

LeeNavigationController *NV3 = [[LeeNavigationController alloc]initWithRootViewController:threeVC];

threeVC.title = @"新闻";

self.viewControllers = @[NV1,NV2,NV3];

}

@end

@interface LeeButton : UIButton

- (instancetype)initWithTitle:(NSString *)title AndImage:(UIImage *)image AndSelectImage:(UIImage *)selectImage AndFrame:(CGRect)frame;

@end

#import "LeeButton.h"

@interface LeeButton()

@property (nonatomic, weak)UIImageView *leeView;

@property (nonatomic, weak)UILabel     *leeLabel;

@property (nonatomic, strong)UIImage   *norImg;

@property (nonatomic, strong)UIImage   *selImg;

@end

@implementation LeeButton

- (instancetype)initWithTitle:(NSString *)title AndImage:(UIImage *)image AndSelectImage:(UIImage *)selectImage AndFrame:(CGRect)frame

{

self = [super initWithFrame:frame];

if (self) {

CGFloat width = self.frame.size.width;

CGFloat height = self.frame.size.height;

CGFloat imageWH = 30;

//添加imageView

UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake((width - imageWH)*0.5, 5, imageWH, imageWH)];

imageView.backgroundColor = [UIColor clearColor];

imageView.contentMode = UIViewContentModeScaleAspectFit;

imageView.image = image;

[self addSubview:imageView];

self.leeView = imageView;

//添加Label

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(imageView.frame), width, height - CGRectGetMaxY(imageView.frame))];

label.backgroundColor = [UIColor clearColor];

label.textAlignment = NSTextAlignmentCenter;

label.font = [UIFont systemFontOfSize:10];

label.textColor = [UIColor whiteColor];

label.text = title;

[self addSubview:label];

self.leeLabel = label;

self.norImg = image;

self.selImg = selectImage;

}

return self;

}

- (void)setSelected:(BOOL)selected

{

[super setSelected:selected];

NSLog(@"111");

if (selected) {

self.leeView.image = self.selImg;

}else{

self.leeView.image = self.norImg;

}

}

@end

自定义导航栏 tabBarController 笔记的更多相关文章

  1. iOS 自定义导航栏笔记

    一.UINavigationBar的结构 导航栏几乎是每个页面都会碰到的问题,一般两种处理方式:1.隐藏掉不显示 2.自定义 1. 添加导航栏 TestViewController * mainVC ...

  2. 分别用ToolBar和自定义导航栏实现沉浸式状态栏

    一.ToolBar 1.在build.gradle中添加依赖,例如: compile 'com.android.support:appcompat-v7:23.4.0' 2.去掉应用的ActionBa ...

  3. swift 自定义导航栏颜色

    func setNavigationApperance(){ //自定义导航栏颜色 [self.navigationController?.navigationBar.barTintColor = U ...

  4. ios7以上自定义导航栏标题的字体大小及颜色的方法

    自定义导航栏的字体和颜色,只需要自定义一个lable,然后将lable添加到导航栏的titleview中就可以了 代码如下 UILabel *label = [[UILabel alloc] init ...

  5. 微信小程序自定义导航栏

    微信小程序需要自定义导航栏,特别是左上角的自定义设置,可以设置返回按钮,菜单按钮,配置如下: 1.在app.json的window属性中增加: navigationStyle:custom 顶部导航栏 ...

  6. iOS:自定义导航栏,随着tableView滚动显示和隐藏

    自定义导航栏,随着tableView滚动显示和隐藏 一.介绍 自定义导航栏是APP中很常用的一个功能,通过自定义可以灵活的实现动画隐藏和显示效果.虽然处理系统的导航栏也可以实现,但是这个是有弊端的,因 ...

  7. 微信小程序 - 自定义导航栏(提示)

    点击下载: 自定义导航栏示例

  8. 微信小程序——自定义导航栏

    微信头部导航栏可能通过json配置: 但是有时候我们项目需求可能需要自定义头部导航栏,如下图所示: 现在具体说一下实现步骤及方法: 步骤: 1.在 app.json 里面把 "navigat ...

  9. 微信小程序-如何自定义导航栏(navigationStyle)?

    小程序是越来越开放了,微信版本 6.6.0可以自定义导航? 先了解下app.json中window配置navigationStyle属性,即导航栏样式,仅支持 default/custom.custo ...

随机推荐

  1. 【mybatis】使用mybatis框架中踩过的坑

    好久没来记录一下自己的学习情况,最近都在学框架,今天来记录一下关于mybatis框架的学习过程中碰过的一些问题: 以下内容可能稍微有点凌乱,因为是把之前遇到过的错误或异常都集中一起了,不过我已经把问题 ...

  2. NIO学习笔记

    零.前言 这里整理摘录了我了解NIO的一些笔记. 参考资料: 1.深入浅出NIO之Channel.Buffer 2.深入浅出NIO之Selector实现原理 3.Java NIO vs. IO 一.N ...

  3. Python库 - Albumentations 图片数据增强库

    Python图像处理库 - Albumentations,可用于深度学习中网络训练时的图片数据增强. Albumentations 图像数据增强库特点: 基于高度优化的 OpenCV 库实现图像快速数 ...

  4. Docker端口映射

    Docker端口映射是指将容器内应用的服务端口映射到本机宿主机器.当要在宿主机外部访问Docker内部应用时,需要对容器内应用端口进行映射. 一.容器启动时指定端口映射 容器运行时可以通过-p 或 - ...

  5. .NET Core 微服务实例

    关于微服务,MSDN给出了定义和架构图:https://docs.microsoft.com/zh-cn/azure/architecture/guide/architecture-styles/mi ...

  6. JAVA值类型和引用类型的区别

    java这两种数据类型分别有哪些? java 中的数据类型分为两大类:值类型(基本数据类型)和引用类型(复合数据类型) 一:值类型: 整数类型(byte,short,int,long)     浮点类 ...

  7. 用grunt对css代码进行压缩

    1.先安装Node.js环境 Grunt和 Grunt 插件是通过 npm 安装并管理的,npm是 Node.js 的包管理器.Node.js的下载链接 安装完后进行验证 2.安装grunt及插件 通 ...

  8. Charles抓https请求详细步骤

    1.电脑上安装好Charles 2.电脑上安装证书 (1)点击Help - SSL Proxying - Install Charlse Root Certificate (2)在电脑上找到证书.此时 ...

  9. PlayFramework 一步一步来 之 页面模板引擎

    Play的魔板引擎本人认为可以说是为full stack Developers量身打造的功能.在原有的html页面基础上,只需要在html文件名后缀名前面加上”.scala“,就可以在页面上写Scal ...

  10. python3 第二十九章 - 内置函数之tuple相关

    Python元组包含了以下内置函数 序号 方法及描述 实例 1 len(tuple)计算元组元素个数. >>> tuple1 = ('Google', 'Baidu', 'Taoba ...