UITabBarController — 标签视图控制器

2023-05-16

UITabBarController — 标签视图控制器

UITabBarController 分为三层结构:

(1).tab bar
(2.)Custom Content
(3.). Tab bar controller View

UITabBarController 有以下重要属性:

(1).viewControls 显示的视图控制器
(2).tabBar 标签栏
(3).delegate 代理
(4).selectedindex 选中某个tabBarItme

UITabBar

(1).tabBar是UITabBar对象,包含多个UIBarItem, 每一个tabBarItem对应一个ViewController ,tabBar的高度是49
(2).当tabBarItem超过5个时,系统会自动增加一个更多按钮,点击更多按钮,没有在底部出现的那些按钮会议列表形式显示出来

UITabBar 的属性

(1).tintColor
(2).barTintColor
(3).图像设置

tabBarItem可以设置title . image . badgeValue

可以用系统的样式创建tabBarItem

1.创建一个视图控制器对象

代码:

FirstViewController *firstVC=[[FirstViewController alloc] init];

2.创建第一个naVC

代码:

UINavigationController *firstNaVC=[[UINavigationController alloc] initWithRootViewController:firstVC];

3.创建tabbar上的按钮及其内容(这种方法是系统方法)

代码:

firstVC.tabBarItem =[[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemHistory tag:1000] autorelease];
  (1). 按钮上添加”+99”的符号      
firstVC.tabBarItem.badgeValue =@"+99";
  (2).用自定义的方法创建:
SecondViewController *secondVC=[[SecondViewController alloc] init];
    UINavigationController *secondNaVC=[[UINavigationController alloc] initWithRootViewController:secondVC];
    secondVC.tabBarItem =[[[UITabBarItem alloc] initWithTitle:@"朋友圈" image:[UIImage imageNamed:@"缩放.png"] selectedImage:[UIImage imageNamed:@"加号.png"]] autorelease];
 (3). 创建第三个(第三种创建方法)
    ThirdViewController *thirdVC=[[ThirdViewController alloc] init];
    UINavigationController *thirdNaVC=[[UINavigationController alloc] initWithRootViewController:thirdVC];
    thirdNaVC.tabBarItem=[[[UITabBarItem alloc] initWithTitle:@"设置" image:[UIImage imageNamed:@"加号.png"] tag:1001] autorelease];

4.按钮创建好,然后创建一个UITabBarController让所有的按钮显示出来

代码:

UITabBarController *tabVC=[[UITabBarController alloc] init];

5.tabbarController 通过一个数组来管理所有要显示出来的naVC

代码:

 tabVC.viewControllers =@[firstNaVC,secondNaVC,thirdNaVC,fourNaVC,fiveNaVC,sixNaVC];
self.window.rootViewController =tabVC;

6.对tabbar进行外观设置(取消透明度)

代码:

tabVC.tabBar.translucent =NO;

7.背景颜色

代码:

tabVC.tabBar.barTiniColor =[UIColormagentaColor];

8.点击之后的选中颜色

代码:

 tabVC.tabBar.tintColor=[UIColor blackColor];

9.设置代理人

代码:

tabVC.delegate=self;

10.刚开始停留的页面下标

代码:

tabVC.selectedIndex =2;

11.方法:

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
 设置badageValue nil 去掉全部    
viewController.tabBarItem.badgeValue=nil;
    // 或者(效果略微不同)
  @“” 还剩一个小圆点
//    viewController.tabBarItem.badgeValue=@""'

}

12.在第一个视图中创建一个TableView

tableView的高度要 减掉tabBar的高度49 和navigationBar的高度64

13.在tableview的第二个协议中的if(!cell)cell创建中,添加一个长按手势和button

代码:

if (!cell) {
        cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease];
        //在这里创建长按手势和一个button,也是为了避免重复创建,在重复使用cell的同时,也同时使用了长安手势和button按钮
        UILongPressGestureRecognizer *longPress=[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(click:)];
        [cell addGestureRecognizer:longPress];
        [longPress release];
        UIButton *button =[UIButton buttonWithType:UIButtonTypeSystem];
        button.frame =CGRectMake(200, 20, 100, 30);
        [button setTitle:@"点击" forState:UIControlStateNormal];
        [cell addSubview:button];

    }

14.在长按手势的方法中可以进行以下操作:

代码:

-(void)click:(UILongPressGestureRecognizer *)longPress{
    NSLog(@"111");
    // 通过手势,找到手势添加的cell
    UITableViewCell *cell = (UITableViewCell *)longPress.view;
 // 创建一个快捷菜单
    UIMenuController *menu =[UIMenuController sharedMenuController];
 // 给这个快捷菜单进行定位
    [menu setTargetRect:cell.frame inView:cell.superview];
// 让菜单可以显示出来
    [menu setMenuVisible:YES animated:YES];
  // 如果想使用自定义的功能
    UIMenuItem *flag =[[UIMenuItem alloc] initWithTitle:@"测试" action:@selector(flag)];
// 把这个按钮放到快捷菜单上
    [menu setMenuItems:@[flag]];
    // 按钮如果不实现,无论系统还是自定义,如果不实现对应的方法,不会添加到快捷菜单上

}

15.快捷菜单捆绑了一个方法,这个方法必须实现,如果不实现,快捷菜单没有办法显示

代码:

-(BOOL)canBecomeFirstResponder{
    return YES;
}

16.以下系统给定的显示快捷菜单

-(void)delete:(id)sender{
    NSLog(@"删除");
}
-(void)copy:(id)sender{
    NSLog(@"复制");
}

-(void)select:(id)sender{
    NSLog(@"选择");
}

17. 也可以添加自定义

代码:

-(void)flag{
    NSLog(@"111");
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

UITabBarController — 标签视图控制器 的相关文章

随机推荐

  • java操作zip压缩文件加密码和解密工具类

    java操作zip压缩文件加密码和解密工具类 lt zip压缩文件工具类 gt lt dependency gt lt groupId gt net lingala zip4j lt groupId gt lt artifactId gt
  • 在CentOS7虚拟机中安装mysql5.7

    写在前面 xff1a 安装环境 xff1a CentOS7虚拟机 xff1b 安装软件 xff1a mysql5 7版本 xff1b 安装时需要切换为root用户权限 安装步骤 xff1a 1 添加官方的yum源 xff0c 创建并编辑my
  • wsl报0x80040326

    今天 开始 运行 wsl 跳出来一个窗口一闪没了 开始 运行 cmd wsl 看到2行报错信息 xff1a Error 0x80040326 Error code Wsl Service CreateInstance 0x80040326
  • VTK笔记——vtkCamera的理解和用法

    其实 xff0c 网上有不少介绍VTK Camera的内容 在3D图形学中 xff0c 相机对于渲染对象来说是必不可少的 我们可以通过它来观察物体 xff0c 包括执行放大缩小 移动相机等操作 xff0c 所以它是我们需要了解的基础和重要的
  • 树莓派4安装Ubuntu20.10桌面版记录(64位系统arm架构desktop版)

    前言 xff1a 这是我在树莓派4上安装Ubuntu20 10桌面版 xff08 64位arm xff09 总结的一些坑 xff0c 欢迎互相交流 xff01 我的博客 xff1a https www 515code com 一 准备 下载
  • 计算机二级C语言基础选择易错题及答案解析(四)

    1 设有定义 char s 81 int i 61 0 以下不能将一行 不超过80个字符带有空格的字符串正确读入的语句或语句组是 解析 xff1a 字符串的输入不能用 span class token function scanf span
  • Ubuntu解决无线被禁用的方法

    查看当前wifi开关的状态 xff0c 有可能是软件block xff0c 也有可能是硬件block 终端输入命令 xff1a rfkill list all 返回电脑目前安装的所有网卡驱动 xff1a 0 ideapad wlan Wir
  • UITabBarController with hidden UITabBar

    None of these solutions I 39 ve been able to find here or elsewhere to hide a UITabBar as part of a UITabBarController w
  • debian9.12的硬盘安装过程一

    下载debian旧版网址 首先 xff0c 找旧版就是一路搜 xff0c 官网只有10 3 xff0c 所以把搜的结果给大家看看 xff0c 减少小白搜索的时间 http cdimage debian org cdimage archive
  • debian 取消合上笔记本盖子休眠

    如何取消debian合盖休眠 需要配置Login Manager 的配置文件 xff08 logind conf xff09 目录位置 xff1a etc systemd logind conf 打开文件如下 xff1a NAutoVTs
  • Ubuntu18.04下NVIDIA驱动安装

    安了一天 xff0c 在网上找了无数教程也没能成功 xff0c 就在准备换系统的时候发现了这篇文章 xff0c 真的安装上了记录一下 xff0c 转自https blog csdn net fengyuechengshi495 articl
  • openstack新秀:manila框架及知识点介绍

    manila 组成部分 xff1a 3类服务 xff08 share api scheduler xff09 一个消息队列 数据库 manila api 接受并验证REST请求 xff0c 通过客户端及路由进行转发 manila sched
  • Centos & Ubuntu Xrdp 远程登录

    Centos xrdp Ubuntu xrdp xrdp 0 4 xff08 含 xff09 以下版本 xff0c 对windows 7支持不是很好 xff0c 建议使用0 5 xff08 含 xff09 以上版本 一 Centos Xrd
  • Centos7安装Gitlab-ce(gitlab社区版)15+版本

    弯路 xff1a 在gitlab官网下载了gitlab ee镜像 xff0c 离了个大谱 xff0c gitlab ee是企业版 xff0c 我们要装的自然是社区版 xff08 免费 xff09 gitlab ce 正路 xff1a 安装依
  • DD Windows 一键脚本,包含GCP谷歌云Oracle甲骨文

    说明 无限制全自动dd安装Windows突破没有VNC 没有救援模式 内存比dd包小的限制使用Debian Live CD中的busybox做中间媒介 经过复杂的处理使本机的网络参数传进Windows操作系统中即使没有DHCP能够让Wind
  • PWM输出实验

    第十四章 PWM输出实验 上一章 xff0c 我们介绍了 STM32的通用定时器TIM3 xff0c 用该定时器的中断来控制DS1的闪烁 xff0c 这一章 xff0c 我们将向大家介绍如何使用STM32的TIM3来产生PWM输出 在本章中
  • GINav 学习笔记(持续更新中~)

    GINav 学习笔记 环境 xff1a win10 matlab 2020a 文章目录 GINav 学习笔记 数据处理部分 xff1a 数据文件类型 xff1a o文件和n文件和p文件区别DCB Differential Code Bias
  • 洛谷-1080 国王游戏

    题目描述 恰逢 H H国国庆 xff0c 国王邀请 n 位大臣来玩一个有奖游戏 首先 xff0c 他让每个大臣在左 右手上面分别写下一个整数 xff0c 国王自己也在左 右手上各写一个整数 然后 xff0c 让这 n 位大臣排成一排 xff
  • AJAX在ASP.NET中的应用(三)——微软的AJAX_Extensions

    前言 xff1a 不只普通民众是傻瓜 xff0c 软件开发工程师同样也是傻瓜 微软的软件产品开发指导理念是路人皆知的 xff0c 当初我踏入软件行业时由于没有洞悉微软的这个本质 xff0c 导致现在已经是上了贼船难再下了 算了 xff0c
  • UITabBarController — 标签视图控制器

    UITabBarController 标签视图控制器 UITabBarController 分为三层结构 1 tab bar 2 Custom Content 3 Tab bar controller View UITabBarContro