//  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. 2013 French Open Semifinal Press

    http://v.youku.com/v_show/id_XNTY4MTgzOTEy.html?firsttime=0 Novak, can you take any confirt   for qu ...

  2. [AngularJS] Accessing Scope from The Console

    Using Angular, you can actually access the scope and other things from the console, so when you have ...

  3. System.setProperty()

    /*  * 设置指定键对值的系统属性  * setProperty (String prop, String value);  *  * 參数:  * prop - 系统属性的名称.  * value ...

  4. IDEA 升级14.1提示org/hibernate/build/gradle/publish/auth/maven/AuthenticationManager:Unsupported major.minor version 51.0

    在看到“Unsupported major.minor version 51.0”这样的错误描述时,就基本可以肯定是jdk版本不正确导致.但是提示的类非业务系统,而是来自IDEA.因此去其官网检索了下 ...

  5. oracle数据迁移

    通过这个文章演示一下Oracle的表空间迁移流程以及需要注意的诸多事项. 实验目标:将ora10g数据库实例上的表空间TBS_SEC_D迁移到secooler数据库实例上操作系统:Redhat 5.3 ...

  6. 功能分解——Android下画分时图与k线图有感

    最近工作极度繁忙,已经好久没有更新博客了,总感觉要是再不抽空总结总结点东西,分分钟就会被懒惰的状态给打到了.同时也希望同学们谨记,如果你已经决定要坚持某些正确的东西,比如背完某章单词,看一完本书抑或是 ...

  7. .net 后台获取当前请求的设备

    检查当前发起请求的设备是手持设备还是电脑端  以便显示不同的视图 public static bool CheckIsMobile(HttpRequestBase req) { bool flag = ...

  8. excel 批量替换换行符

    在excel批量替换换行符操作步骤: 全选需要查找换行符的范围 CTRL+H调出查找和替换 在查找内容内输入"ctrl+enter"两个组合键 点击查找全部即可. 在excel中输 ...

  9. EF——继承映射关系TPH、TPT和TPC的讲解以及一些具体的例子 05 (转)

    EF里的继承映射关系TPH.TPT和TPC的讲解以及一些具体的例子   本章节讲解EF里的继承映射关系,分为TPH.TPT.TPC.具体: 1.TPH:Table Per Hierarchy 这是EF ...

  10. ubuntu16.04 编译安装mysql5.7.x,以及配置使用

    編譯與安裝: 源码下载地址:http://dev.mysql.com/downloads/mysql/    选择Generic Linux (Architecture Independent), C ...