这里的背景跟上面的差点儿相同

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">

只是这里要用到AppDelegate的单例进行传值

首先到AppDelegate.h文件里

<span style="color:#FF0000;">#import <UIKit/UIKit.h>

@interface WJJRootViewController : UITabBarController

//声明一UIButton属性 来记录当前按下的button
@property (nonatomic,strong) UIButton * selectedButton; @end</span>

然后到RootViewController.h中

#import <UIKit/UIKit.h>

@interface WJJRootViewController : UITabBarController

//声明一UIButton属性 来记录当前按下的button
@property (nonatomic,strong) UIButton * selectedButton; @end

接下来进入到RootViewController.m中

#import "WJJRootViewController.h"
#import "WJJFirstViewController.h"
#import "WJJSecondViewController.h"
#import "WJJThirdViewController.h"
#import "WJJForthViewController.h"
<span style="color:#FF0000;">#import "WJJAppDelegate.h"</span> @interface WJJRootViewController () @end @implementation WJJRootViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} //标签栏的高度是49像素 - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self createViewControllers];
[self createMyTabBar];
} - (void)createMyTabBar{ //获取系统tabBar的位置
CGRect frame = self.tabBar.frame; //创建一个UIView
UIView * tabBarView = [[UIView alloc] initWithFrame:frame];
tabBarView.backgroundColor = [UIColor blackColor];
[self.view addSubview:tabBarView]; <span style="color:#FF0000;">//把创建的tabBarView赋值给delegate的tabBarView属性
WJJAppDelegate * delegate = [UIApplication sharedApplication].delegate;
delegate.tabBarView = tabBarView;
</span> //循环创建四个按钮 放到tabBarItem上
CGFloat xSpace = (self.view.frame.size.width - 4 * 30) / 5;
for (int i = 0; i < 4; i++) {
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(xSpace + i * (30 + xSpace), 9.5, 30, 30);
//按钮寻常状态下得图片
[button setImage:[UIImage imageNamed:[NSString stringWithFormat:@"tab_%d.png",i]] forState:UIControlStateNormal];
//按钮点击时得图片颜色
[button setImage:[UIImage imageNamed:[NSString stringWithFormat:@"tab_c%d.png",i]] forState:UIControlStateSelected];
[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
button.tag = 100 + i;
[tabBarView addSubview:button]; if (100 == button.tag) {
//把第一个创建的按钮 设为默认
button.selected = YES;
//把点击的按钮 记录下来
self.selectedButton = button;
}
}
} - (void)click:(UIButton *)button{ self.selectedButton.selected = YES;
//运行以下代码 就能使得按不同的button调到不同界面
self.selectedIndex = button.tag - 100;
button.selected = YES;
//把点击的按钮再次记录下来
self.selectedButton = button; } - (void)createViewControllers{
WJJFirstViewController * first = [[WJJFirstViewController alloc] init]; UINavigationController * firstNav = [[UINavigationController alloc] initWithRootViewController:first]; WJJSecondViewController * second = [[WJJSecondViewController alloc] init]; WJJThirdViewController * third = [[WJJThirdViewController alloc] init]; WJJForthViewController * forth = [[WJJForthViewController alloc] init]; self.viewControllers = @[firstNav,second,third,forth];
} - (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
//当此界面出现时 让系统的标签栏隐藏
self.tabBar.hidden = YES;
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

然后进入到FirstViewController.m中 跟之前的是一样的代码

#import "WJJFirstViewController.h"
#import "WJJFirstChildViewController.h" @interface WJJFirstViewController () @end @implementation WJJFirstViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor greenColor];
[self createButton];
} - (void)createButton{ UIButton * rightButton = [UIButton buttonWithType:UIButtonTypeSystem];
rightButton.frame = CGRectMake(0, 0, 50, 20);
[rightButton setTitle:@"下一页" forState:UIControlStateNormal];
[rightButton addTarget:self action:@selector(nextPage) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem * rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
self.navigationItem.rightBarButtonItem = rightBarButtonItem; } - (void)nextPage{ WJJFirstChildViewController * child = [[WJJFirstChildViewController alloc]init];
[self.navigationController pushViewController:child animated:YES]; } - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

再次进入到FirstChildViewController.m 中

#import "WJJFirstChildViewController.h"
<span style="color:#FF0000;">#import "WJJAppDelegate.h"
</span>
@interface WJJFirstChildViewController () @end @implementation WJJFirstChildViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor blueColor];
} //用AppDelegate的单例模式传值 //以下两个方法是进入到子界面时 tabBarView消失或隐藏
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
<span style="color:#FF0000;"> WJJAppDelegate * delegate = [UIApplication sharedApplication].delegate;
delegate.tabBarView.hidden = YES;</span>
} - (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
<span style="color:#FF0000;">WJJAppDelegate * delegate = [UIApplication sharedApplication].delegate;
delegate.tabBarView.hidden = NO;</span> } - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

在这里。我们是用得Appdelegate的单例模式进行对自己定义的tabBarView进行传值 设置它的隐藏 就是红色字体的代码

Snail—UI学习之自己定义标签栏UITabBarController的更多相关文章

  1. Snail—UI学习之自己定义通知NSNotification

    背景是:一个界面跳转到第二个界面 然后 第一个界面发了一个通知  然后第二个界面收到这个通知后 把里面的数据取出来 在RootViewController.m中写入以下代码 #import " ...

  2. Snail—UI学习之得到某组件的方法

    第一种方法:依据传入函数的參数对象的tag属性区分 比方 多个button运行同一个方法,可是不同的方法运行时.里面的逻辑又不一样 那就得加以区分 这时能够用tag来差别 //再新建一个Button ...

  3. Snail—UI学习之UITextField

    简单看一下UITextField的属性 - (void)createTextField{ UITextField * textField = [[UITextField alloc] initWith ...

  4. Snail—UI学习之导航视图控制器UINavigationController(系统)

    背景 有一个根视图控制器 然后跳转到第一个界面  第一个界面能够返回到根视图 也能够跳转到第二个视图 第二个视图能够直接返回到根视图 新建三个ViewController    RootViewCon ...

  5. Android UI学习 - ListView (android.R.layout.simple_list_item_1是个什么东西)

    Android UI学习 - ListView -- :: 标签:Android UI 移动开发 ListView ListActivity 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始 ...

  6. IOS开发-UI学习-sqlite数据库的操作

    IOS开发-UI学习-sqlite数据库的操作 sqlite是一个轻量级的数据库,它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存就够了,而且它的处理速度比Mysql.PostgreSQL这 ...

  7. 适合新手小白的UI学习路线完整版

    UI设计是很多年轻人活着想转行学习的人的新职业目标,越来越多的人看到UI设计良好的就业发展前景,纷纷投入到UI设计的大军中来,想学习UI设计,很多小白并不知道从何开始学起,用什么样的方法去学习,所以今 ...

  8. Swift学习——类的定义,使用,继承,构造等(五)

    Swift学习--类的定义,使用.继承,构造等(五) 类的使用说明 1 使用class和类名来创建一个类名,比如: class student 2 类中属性的声明和常量和变量一样,唯一的差别就是他们的 ...

  9. python学习7—函数定义、参数、递归、作用域、匿名函数以及函数式编程

    python学习7—函数定义.参数.递归.作用域.匿名函数以及函数式编程 1. 函数定义 def test(x) # discription y = 2 * x return y 返回一个值,则返回原 ...

随机推荐

  1. 4.cocos场景和层的调用

    调用关系: AppDeligate.cpp bool AppDelegate::applicationDidFinishLaunching() { // initialize director aut ...

  2. 【Pycharm】【HTML】注释问题

    学习HTML中,遇到的注释前存在空行的问题: 只要找到Pycharm设置中:勾选去掉即可

  3. python学习日记-180823

    列表 a=[ ] 1.负数下标:a=[-1]指的是列表a最后一个下标,-2指倒数第二个下标 2.切片——利用切片获得子列表 a[1:4]——'1'切片开始处的下标,‘4’切片结束处的下标(不包括此下标 ...

  4. CSS控制显示超出部分,用省略号显示

    经常使用.可是常忘,我又不是写css的.所以记下来: 先设置一下限制的宽度, display:block; white-space:nowrap; overflow:hidden; text-over ...

  5. 使用 Bluemix™ Live Sync 高速更新 Bluemix 上执行的应用程序实例

    假设您要构建 Node.js 应用程序,那么能够使用 IBM® Bluemix® Live Sync 高速更新 Bluemix 上的应用程序实例,并像在桌面上进行操作一样进行开发,而无需又一次部署.执 ...

  6. c++运算符重载笔记

    运算符重载的概念:给原有的运算符赋予新的功能: 比如:+ 不仅可以做算术运算也可以连接俩个字符串 一元运算符:只与一个操作数进行运算 比如 正负号 运算符重载的本质是:函数重载. <<与& ...

  7. 78.pipe多管道云端,客户端通信

    压力测试截图: 云端 定义管道缓存区大小,最多连接数量(线程个数),当前线程个数,管道名字 //缓冲区大小 #define SIZE 4096 //最多连接数量 #define MAX_CONNECT ...

  8. 团队作业-Beta冲刺(1)

    这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass2 这个作业要求在哪里 https://edu.cnblo ...

  9. yarn的安装和使用

    yarn的简介: Yarn是facebook发布的一款取代npm的包管理工具. yarn的特点: 速度超快. Yarn 缓存了每个下载过的包,所以再次使用时无需重复下载. 同时利用并行下载以最大化资源 ...

  10. MySQL集群搭建详解

    概述 MySQL Cluster 是MySQL 适合于分布式计算环境的高实用.可拓展.高性能.高冗余版本,其研发设计的初衷就是要满足许多行业里的最严酷应用要求,这些应用中经常要求数据库运行的可靠性要达 ...