//  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的更多相关文章

  1. TabBarViewController的创建以及渐变隐藏

    // CustomTabBarViewController.h #import <UIKit/UIKit.h> @interface CustomTabBarViewController ...

  2. ModelFirst的CRUD

    创建实体:

  3. 完全定制UITabBarViewController

    完全定制UITabBarViewController 效果   源码 https://github.com/YouXianMing/iOS-Project-Examples 中的 TotalCusto ...

  4. 自定义的tabBarController的几种方法

    本文转载自:http://blog.sina.com.cn/s/blog_79c5bdc30100t88i.html 我自己实现的一种可以很方便的实现更换TabBarController图片的方法,代 ...

  5. iOS:探究视图控制器的转场动画

    一.介绍 在iOS开发中,转场动画的使用无处不见,不只是我们自己更多的使用UIViewblock动画实现一个转场动画,其实,在我们实现VC控制器跳转的时候都是转场动画的实现,例如标签栏控制器的切换.模 ...

随机推荐

  1. replace into

    讨人喜欢的 MySQL replace into 用法(insert into 的增强版) 在向表中插入数据的时候,经常遇到这样的情况:1. 首先判断数据是否存在: 2. 如果不存在,则插入:3.如果 ...

  2. iOS开发——数据持久化Swift篇&(四)CoreData

    CoreData import CoreData class ViewController: UIViewController { override func viewDidLoad() { supe ...

  3. 20条IPTables防火墙规则用法!

    导读 管理网络流量是系统管理员必需处理的最棘手工作之一,我们必需规定连接系统的用户满足防火墙的传入和传出要求,以最大限度保证系统免受攻击.很多用户把 Linux 中的 IPTables 当成一个防火墙 ...

  4. MyBatis 环境搭建

    1.为什么我们学习框架? 提高开发效率,框架是别人写好的工具类,我们需要遵循其规则进行操作 2.我们学习哪些框架 A.持久层框架:MyBatis 什么是持久化? 狭义:把数据永久性的保存到数据当中 广 ...

  5. Amazon Launches FBA Export to Expand Beyond Media Categories

    Amazon launched a new program called FBA Export for third-party sellers to help them export products ...

  6. NSBlockOperation添加多个任务

    //创建一个队列 NSOperationQueue *operation=[[NSOperationQueue alloc]init]; //把任务放在NSBlockOperation里面 NSBlo ...

  7. Socket 使用笔记与注意事项(一)

    SocketAsyncEventArgs 1.该参数可以重复使用. 2.SocketAsyncEventArgs 的事件执行触发之后可以使用. 3.SocketAsyncEventArgs 的事件还在 ...

  8. [Android]Handler的消息机制

    最经面试中,技术面试中有一个是Handler的消息机制,细细想想,我经常用到的Handler无非是在主线程(或者说Activity)新建一个Handler对象,另外一个Thread是异步加载数据,同时 ...

  9. [转]关于position 的 static、relative、absolute、fixed、inherit

    本文转自:http://www.56770.com/faq/list/?id=410 position 有五个值:static.relative.absolute.fixed.inherit. sta ...

  10. 怒刷DP之 HDU 1160

    FatMouse's Speed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Su ...