CustomTabBarViewController
// AppDelegate.m
// CustomTabBar
//
// Created by qianfeng on 15/7/9.
// Copyright (c) 2015年 qianfeng. All rights reserved.
// #import "AppDelegate.h"
#import "CustomTabBarViewController.h"
@interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
CustomTabBarViewController *customTabBar= [[CustomTabBarViewController alloc]init];
self.window.rootViewController=customTabBar;
return YES;
} //
// ViewController.h
// CustomTabBar
//
// Created by qianfeng on 15/7/9.
// Copyright (c) 2015年 qianfeng. All rights reserved.
// #import <UIKit/UIKit.h> @interface ViewController : UIViewController @end // ViewController.m
// CustomTabBar
//
// Created by qianfeng on 15/7/9.
// Copyright (c) 2015年 qianfeng. All rights reserved.
// #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
// CustomTabBarViewController.h
// CustomTabBar
//
// Created by qianfeng on 15/7/9.
// Copyright (c) 2015年 qianfeng. All rights reserved.
// #import <UIKit/UIKit.h> @interface CustomTabBarViewController : UITabBarController @end //
// CustomTabBarViewController.m
// CustomTabBar
//
// Created by qianfeng on 15/7/9.
// Copyright (c) 2015年 qianfeng. All rights reserved.
// #import "CustomTabBarViewController.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"
#import "FourthViewController.h"
@interface CustomTabBarViewController () @end @implementation CustomTabBarViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
//隐藏系统tabbar
self.tabBar.hidden=YES; //创建视图控制器数组
[self creatViewController]; //
//创建tabbar
UIImageView *bgView =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"tabbg"]];
bgView.tag=499;
bgView.frame=CGRectMake(0, self.view.frame.size.height-49, self.view.frame.size.width, 49);
[self.view addSubview:bgView];
self.view.backgroundColor=[UIColor cyanColor];
//打开用户交互使能
bgView.userInteractionEnabled=YES;
CGFloat space =(self.view.frame.size.width-4*30)/5; for (int i=0; i<4; i++) {
UIButton *btn =[UIButton buttonWithType:UIButtonTypeCustom];
btn.frame=CGRectMake(space+i*(30+space),9, 30, 30);
NSString *imageName =[NSString stringWithFormat:@"tab_%i",i];
NSString *selectimageName =[NSString stringWithFormat:@"tab_c%i",i];
//设置正常状态图片
[btn setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
//设置选中状态图片
[btn setBackgroundImage:[UIImage imageNamed:selectimageName] forState:UIControlStateSelected];
//添加点击事件
[btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
btn.tag=100+i; //设置选中状态的btn
if(btn.tag==100)
{
btn.selected=YES;
}
[bgView addSubview:btn];
} UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(space, 40, 30, 4)];
label.backgroundColor=[UIColor orangeColor];
label.tag=498;
[bgView addSubview:label]; } -(void)btnClicked:(UIButton *)btn
{ //self.selectedIndex=3;
//记录选中的button
NSInteger index =btn.tag-100;
UIView *bgView =[self.view viewWithTag:499];
for (UIView *view in bgView.subviews) {
if(view.tag!=498)
{
if(btn.tag==view.tag)
{
//btn.selected=YES;
((UIButton *)view).selected=YES; }
else{
//btn.selected=NO;
((UIButton *)view).selected=NO;
}
}
}
self.selectedIndex=index; UILabel *label =(UILabel *)[bgView viewWithTag:498];
CGFloat space =(self.view.frame.size.width-4*30)/5;
[UIView animateWithDuration:0.3 animations:^(void){
CGRect frame =label.frame;
frame.origin.x =space+(space +30)*index;
label.frame=frame;
}];
} -(void)creatViewController
{
FirstViewController *firstVC=[[FirstViewController alloc]init];
SecondViewController *secondVC=[[SecondViewController alloc]init];
ThirdViewController *thirdVC=[[ThirdViewController alloc]init];
FourthViewController *fourthVC =[[FourthViewController alloc]init]; NSArray *viewController =[NSArray arrayWithObjects:firstVC,secondVC,thirdVC,fourthVC, nil];
self.viewControllers=viewController;
//self.tabBarController.viewControllers=viewController;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
// FourthViewController.h
// CustomTabBar
//
// Created by qianfeng on 15/7/9.
// Copyright (c) 2015年 qianfeng. All rights reserved.
// #import <UIKit/UIKit.h> @interface FourthViewController : UIViewController @end // FourthViewController.m
// CustomTabBar
//
// Created by qianfeng on 15/7/9.
// Copyright (c) 2015年 qianfeng. All rights reserved.
// #import "FourthViewController.h" @interface FourthViewController () @end @implementation FourthViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor=[UIColor redColor];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} // ThirdViewController.h
// CustomTabBar
//
// Created by qianfeng on 15/7/9.
// Copyright (c) 2015年 qianfeng. All rights reserved.
// #import <UIKit/UIKit.h> @interface ThirdViewController : UIViewController @end // ThirdViewController.m
// CustomTabBar
//
// Created by qianfeng on 15/7/9.
// Copyright (c) 2015年 qianfeng. All rights reserved.
// #import "ThirdViewController.h" @interface ThirdViewController () @end @implementation ThirdViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor=[UIColor blueColor];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} // SecondViewController.h
// CustomTabBar
//
// Created by qianfeng on 15/7/9.
// Copyright (c) 2015年 qianfeng. All rights reserved.
// #import <UIKit/UIKit.h> @interface SecondViewController : UIViewController @end // SecondViewController.m
// CustomTabBar
//
// Created by qianfeng on 15/7/9.
// Copyright (c) 2015年 qianfeng. All rights reserved.
// #import "SecondViewController.h" @interface SecondViewController () @end @implementation SecondViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor=[UIColor cyanColor];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} // FirstViewController.h
// CustomTabBar
//
// Created by qianfeng on 15/7/9.
// Copyright (c) 2015年 qianfeng. All rights reserved.
// #import <UIKit/UIKit.h> @interface FirstViewController : UIViewController @end // FirstViewController.m
// CustomTabBar
//
// Created by qianfeng on 15/7/9.
// Copyright (c) 2015年 qianfeng. All rights reserved.
// #import "FirstViewController.h" @interface FirstViewController () @end @implementation FirstViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor=[UIColor yellowColor];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
CustomTabBarViewController的更多相关文章
- TabBarViewController的创建以及渐变隐藏
// CustomTabBarViewController.h #import <UIKit/UIKit.h> @interface CustomTabBarViewController ...
- ModelFirst的CRUD
创建实体:
- 完全定制UITabBarViewController
完全定制UITabBarViewController 效果 源码 https://github.com/YouXianMing/iOS-Project-Examples 中的 TotalCusto ...
- 自定义的tabBarController的几种方法
本文转载自:http://blog.sina.com.cn/s/blog_79c5bdc30100t88i.html 我自己实现的一种可以很方便的实现更换TabBarController图片的方法,代 ...
- iOS:探究视图控制器的转场动画
一.介绍 在iOS开发中,转场动画的使用无处不见,不只是我们自己更多的使用UIViewblock动画实现一个转场动画,其实,在我们实现VC控制器跳转的时候都是转场动画的实现,例如标签栏控制器的切换.模 ...
随机推荐
- (转)用AGG实现高质量图形输出(二)
本文上接<用AGG实现高质量图形输出(一)>,分别介绍了AGG显示流程中的各个环节. 上次讲了AGG的显示原理并举了一个简单的例子,这一篇文章开始讲AGG工作流程里的每个环节.为了方便对照 ...
- win7远程桌面连接
远程桌面连接 1.在防火墙上设置同意同意远程桌面通过防火墙: 2.为管理员设置password.以便訪问者訪问: 3.我的电脑-右键属性-远程设置-远程-选上"同意远程协助远程这台计算机.同 ...
- MySql 日期格式化函数date_format()
mysql> select date_format(now(),'%Y'); +-------------------------+ | date_format(now(),'%Y') | +- ...
- LINUX 内存结构
1.页框管理 Linux采用4KB页框大小作为标准的内存分配单元.内核必须记录每个页框的状态,这种状态信息保存在一个类型为page的页描述符中,所有的页描述存放在mem_map中.virt_to_pa ...
- 深入解析ext2文件系统之mke2fs
上一遍博文的重点其实将ext2整体的组织框架,我们知道了ext2文件系统由块组组成,每个块组里面的组织形式.我们甚至直接把超级块和组描述符里面的内容,用十六进制形式展现了出来.这篇博文主要讲述如何 ...
- Drawable和Bitmap转换
一.Bitmap转Drawable Bitmap mBitMap=getYourBitMap(); //getYourBitMap()是你获取BitMap的方法 BitmapDrawable mBit ...
- C#面向对象(三)接口实现多态
一.如何用接口实现多态? 1.定义一个接口. using System; using System.Collections.Generic; using System.Linq; using Syst ...
- 【Shell脚本学习8】Shell特殊变量:Shell $0, $#, $*, $@, $?, $$和命令行参数
前面已经讲到,变量名只能包含数字.字母和下划线,因为某些包含其他字符的变量有特殊含义,这样的变量被称为特殊变量. 例如,$ 表示当前Shell进程的ID,即pid,看下面的代码: $echo $$ 运 ...
- Hadoop学习笔记(1) ——菜鸟入门
Hadoop学习笔记(1) ——菜鸟入门 Hadoop是什么?先问一下百度吧: [百度百科]一个分布式系统基础架构,由Apache基金会所开发.用户可以在不了解分布式底层细节的情况下,开发分布式程序. ...
- 使用keil建立标准STM32工程模版(图文详细版!)
1. 模板工程的创建(超级详细版,使用的是keil 4.5版本) 1.1创建工程目录 良好的工程结构能让文件的管理更科学,让开发更容易更方便,希望大家养成良好的习惯,使用具有合理结构的工程目录,当 ...