UITabBarController

2023-05-16

1 UITabBarController的常用属性和方法

一般来说,目前市面上的App很多都是由一个UITabBarController管理着4~5个UINavigationController,然后每个UINavigationController又管理着一组UIViewController对象或者其子类对象(如UITableViewController、UICollectionViewController等)。

在UITabBarController类中,有两个核心属性,分别为viewControllers和tabBar,其分别管理UITabBarController的子控制器以及底部菜单栏的样式。

// viewControllers:用于存储UITabBarController所需要管理的子控制器,通常这些子控制器是UINavigationController类的对象。
@property(nullable, nonatomic, copy) NSArray<__kindof UIViewController *> *viewController;
// tabBar:用于定制tabBar的整体外观样式,例如,背景颜色、背景图片等,需要注意的是:tabBar上每个按钮的样式定制并不由tabBar决定,这个与导航栏navigationBar是类似的。
@property(nonatomic, readonly) UITabBar *tabBar;
// selectedViewController:设置被选中的子控制器,被选中的子控制器会显示被选中的状态。
@property(nullable, nonatomic, assign) __kindof UIViewController (selectedViewController;
// selectedIndex:根据序号设置被选中的子控制器。
@property(nonatomic) NSUInteger selectedIndex;
3.UIViewController类中的tabBarItem与tabBarController
UITabBarController类中也对UIViewController类的属性进行了扩展,增加了tabBarItem这个关键属性,因此,每个子控制器的UITabBarItem样式,其实是在子控制器对象中进行设置的,这样保证了定制的灵活性。
另外,tabBarController属性使每个子控制器都可以获取到管理它的UITabBarController对象。
@interface UIViewController (UITabBarControllerItem)
@property(nullresettable, nonatomic, strong) UITabVarItem *tabBarItem;
@property(nullable, nonatomic, readonly, strong) UITabBarController *tabBarController;
@end

2 UITabBar的常用属性和方法

UITabBar类对象tabBar是UITabBarController中的一个属性,其负责定义底部功能栏的整体外观样式,但每个菜单按钮的样式并不是由UITabBar类对象控制的,而是有各个子控制器中的tabBarItem(UITabBarItem类)属性决定的。

// tintColor:tabBar整体渲染的颜色。
@property(null_resettable, nonatomic, strong) UIColor *tintColor;
// barTintColor:tabBar的整体背景颜色。
@property(nullable, nonatomic, strong) UIColor *barTintColor;
// backgroundImage:为tabBar设置背景图片。
@property(nullable, nonatomic, strong) UIColor *backgroundImage;
// barStyle:tabBar的整体风格样式,默认为白色的,可以改为黑色。
@property(nonatomic) UIBarStyle barStyle;
typedef NS_ENUM(NSInteger, UIBarStyle) {
    UIBarStyleDefault = 0,
    UIBarStyleBlack = 1,
}
// items:获取tabBar上面的所有UITabBarItem类的对象,即底部菜单栏上面的按钮,可以对其样式进行修改。
@property(nullable, nonatomic, copy) NSArray<UITabBarItem *> *items;

3 UITabBarItem的常用属性和方法

UITabBarItem是用于定义底部tabBar上每个按钮样式的类,UITabBarItem对象的设置是在各个子控制器中设置的,即UIViewController类中有一个UITabBarItem类的对象——tabBarItem。

在TabBar上每个按钮都是UITabBarItem类的对象,虽然其看上去是按钮,但UITabBarItem类并不是UIView的子类,而是NSObject的子类,因此,UIView的属性其都不具备。

// UITabBarItem类的实例化方法。该方法需要传递3个参数,分别为每个UITabBarItem的底部文字描述,中间的图片以及选中后显示的图片。需要注意的是,选中状态下文字的颜色需要设置tabBar的tintColor属性。
-(instancetype)initWithTitle:(nullable NSString *)title image:(nullable UIImage *)image selectedImage:(nullable UIImage *)selectedImage;
// badgeValue:每个UITabBarItem对象右上角的提示信息
@property(nullable, nonatomic, copy) NSString *badgeValue;
// badgeColor:iOS 10中新加入的属性,可以定制badge的颜色,默认为红色,也可以修改为其他颜色
@property(nonatomic, readwrite, copy, nullable) UIColor *badgeColor;

5 UITabBarController的代理协议

// 当切换子控制器时调用。可以用于切换控制器时准备界面数据
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;
// 设置子控制器能否被选中。
-(BOOL)taBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController;

 

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

UITabBarController 的相关文章

随机推荐

  • 【Python】用pyecharts绘制我国人口分布和迁移地图

    一直很好奇我国人口分布和迁移情况 xff0c 所以想用Python分析一下 由于我国省份较多 xff0c 把数据放在地图上展示会更加清晰 xff0c 故本文用Python中的pyecharts库进行人口分布和迁移绘图展示 pyecharts
  • 模型评价指标—ROC曲线

    对于分类模型 xff0c 在建立好模型后 xff0c 我们想对模型进行评价 xff0c 常见的指标有混淆矩阵 F1值 KS曲线 ROC曲线 AUC面积等 也可以自己定义函数 xff0c 把模型结果分割成n 100 份 xff0c 计算top
  • 模型评价指标—F1值

    最近空余时间在参加数字中国创新大赛 xff0c 比赛规则是根据模型的F1值对参赛者进行排名 为了更深刻地理解这个指标 xff0c 我最近对它做了一些梳理 xff0c 现在把它分享给更多有需要的人图片 最近在参赛时也发现了一个问题 xff0c
  • 【Python常用函数】一文让你彻底掌握Python中的pivot_table函数

    任何事情都是由量变到质变的过程 xff0c 学习Python也不例外 只有把一个语言中的常用函数了如指掌了 xff0c 才能在处理问题的过程中得心应手 xff0c 快速地找到最优方案 本文和你一起来探索Python中的pivot table
  • python画生肖兔

    2022已经过去 xff0c 2023正在继续 xff0c 希望我们都能在平凡的日子里 xff0c 熠熠生辉 本文介绍运用Python中的turtle库控制函数画生肖兔 xff0c 并设置了2023年幸运词 xff0c 快截屏看看你的幸运词
  • 判断变量是否存在

    来获取一个变量是否存在 xff0c 用 if typeof a 61 34 undefined 34 alert 34 ok 34 xff0c xff0c 而不要去使用 if a 因为如果 a 不存在 xff08 未声明 xff09 则会出
  • Nextcloud 内部服务器错误解决

    在部署nextcloud过程中最后登录页面时出现内部服务器错误 xff0c 心态当时就炸了 在网上找了各种方案 xff0c 但是大部分博主都告诉我是 var lib php session 属组的权限问题 xff0c 或者web目录的权限不
  • golang中的(data race )典型数据竞争问题举例

    示例一 func main var wg sync WaitGroup wg Add 5 for i 61 0 i lt 5 i 43 43 go func fmt Println i Not the 39 i 39 you are loo
  • Jupyter Notebook怎么全选输出的内容?

    Ctrl 43 A 单击 双击 三连击 三连击 xff01 xff01 xff01
  • RetinaNet详细解读

    网络名称RetinaNet发表时间2018年1月作者Tsung Yi Lin Priya Goyal Ross Girshick Kaiming He and Piotr Dollar机构Facebook AI Research FAIR
  • 微信公众号服务器token验证失败?

    很可能是你用了官方的python范例 xff0c 官方的范例是python2的 xff0c 而我用的是python3的 将 map sha1 update list 修改为sha1 61 hashlib sha1 34 34 join li
  • 三分钟学会lightGBM安装及入门指南(一)

    果然标题大法好啊 xff0c 还是成功的让你进来了吧 xff0c xff0c 但是以下都是干货 我的机器环境python3 6 xff0c win7操作系统 xff0c 当然win10也是同样适用的 xff0c 有不懂的可以留言 xff0c
  • 微信小程序文字水平垂直居中对齐问题(完美解决方案)

    我们知道常用的居中对齐方式有很多种例如 xff1a text align center align items center justify content center margin auto 子容器在父容器中居中 但是在view中的文字
  • mac下python matplotlib中文乱码解决方案(亲测可用)!!

    在网上找了一大堆方法 xff0c 花了很久 xff0c 发现不是要安装各种字体就是要改配置 xff0c 而且字体真的不好找也不好安装 就例如下面这两种办法 xff0c mac下根本不管用 xff0c 别人管不管用我不知道 xff0c 反正我
  • python使用threading.Timer实现线程循环任务定时器(一)

    在进行爬虫系统开发的过程中遇到需要间隔一段时间就重复执行的任务的需求 xff0c 就想实现一个线程服务在后台监控数据的抓取状态 xff0c 要想实现定时循环任务的脚本可以使用linux下的crontab命令来执行 xff0c 但是在一个常驻
  • cross_val_score的 scoring参数值解析

    一般我们在模型训练过程中 xff0c 会采用K折交叉验证的方法来验证模型的表现 xff0c 从而进行调参 xff0c 一般我们会用到 sklearn model selection 的 cross val score 方法来计算模型的得分
  • windows 10下 itunes 备份默认存储路径问题

    最近在研究iphone手机备份的问题 xff0c 在使用itunes给手机备份的时候 xff0c 发现C盘空间不够用了 xff0c 于是想把itunes的默认存储路径修改一下 xff0c 在网上查找资料了解了相关操作教程后 xff0c 发现
  • MAC查看与修改系统默认的shell

    查看系统当前默认使用的shell有如下几个方法 一 查看所有的shell cat etc shells 输出 List of acceptable shells for chpass 1 Ftpd will not allow users
  • windows下redis的配置文件(redis.windows.conf)

    redis的配置 Redis默认不是以守护进程的方式运行 xff0c 可以通过该配置项修改 xff0c 使用yes启用守护进程 daemonize yes 当Redis以守护进程方式运行时 xff0c Redis默认会把pid写入redis
  • UITabBarController

    1 UITabBarController的常用属性和方法 一般来说 xff0c 目前市面上的App很多都是由一个UITabBarController管理着4 xff5e 5个UINavigationController xff0c 然后每个