iOS 自定义设置UITabBar 角标 badgeView 的背景色
来源:互联网 发布:js json判断是否有key 编辑:程序博客网 时间:2024/06/08 18:46
UITabBar 角标 badgeView 的默认背景色是红色,有时候也需要根据需求进行修改,但在网上大致寻找了一下,发现有两种主要的处理的方式:
1.完全自定义UITabBar;
2.不使用官方的badgeView,而是对UITabbar进行扩展,自定义一个view或者label,并将其放在UITabBar上;
这里就不上代码了,想了解的可以看这篇文章 : http://www.jianshu.com/p/ccc0d24408fd
3.除了以上两种方式外,还有另外一种方式 ------ 直接对官方的控件进行修改,这种方式也需要对 UITabBar 进行扩展,过程如下:
#import "UITabBar+Custom.h"@implementation UITabBar (Custom)/** * 该方法的调用一定要在设置了tabBarItem.badgeValue 之后使用 */- (void)badgeViews:(void (^)(UIView *badgeView, UILabel *badgeLabel, UIView *badgeBackground))block { if (block) { for (UIView *tabBarButton in self.subviews) { /** 设置badgeView背景色就可设置角标的背景色 */ for (UIView *badgeView in tabBarButton.subviews) { NSString *className = NSStringFromClass([badgeView class]); if ([className rangeOfString:@"BadgeView"].location != NSNotFound) { /** badgeLabel 就是角标上数字显示框 */ UILabel *badgeLabel; /** badgeBackground 在badgeView上可能不存在,如果存在就可以进行自定义修改 */ UIView *badgeBackground; for (UIView *badgeSubview in badgeView.subviews) { NSString *className = NSStringFromClass([badgeSubview class]); if ([badgeSubview isKindOfClass:[UILabel class]]) { badgeLabel = (UILabel *)badgeSubview; } else if ([className rangeOfString:@"BadgeBackground"].location != NSNotFound) { badgeBackground = badgeSubview; } } block(badgeView, badgeLabel, badgeBackground); } } } }}@end
调用该方法场景是这样的
[self.tabBar badgeViews:^(UIView *badgeView, UILabel *badgeLabel, UIView *badgeBackground) { //这里进行相关自定义设置,如:背景色、显示内容,添加背景图片... badgeView.backgroundColor = [UIColor redColor]; }];
0 0
- iOS 自定义设置UITabBar 角标 badgeView 的背景色
- iOS开发:设置 UITabBar 的背景色
- 改变UITabBar的背景色
- 设置标题栏背景色,背景色是自定义背景色
- iOS navigation bar的背景色设置
- iOS UITableViewHeaderFooterView的背景色怎么设置?
- 在iOS8系统下,UITabbar上的item自定义背景色和图片问题
- 在iOS8系统下,UITabbar上的item自定义背景色和图片问题 (
- 在iOS8系统下,UITabbar上的item自定义背景色和图片问题
- 在iOS8系统下,UITabbar上的item自定义背景色和图片问题
- 在iOS8系统下,UITabbar上的item自定义背景色和图片问题
- 设置IOS 状态栏背景色
- 自定义headerView设置背景色无效的解决方案
- iOS开发>>>设置UITableView背景色和选中背景色
- 【IOS开发】UITableViewStyleGrouped类型的UITableView的背景色设置
- 自定义UINavigationBar的背景色
- IOS 设置Section的背景色和字体颜色
- iOS 6/7 UISearchBar的背景色设置
- Seven Puzzle Aizu
- ceph 知识技能树
- 第一次爬虫实战--爬取糗事百科段子
- html5文件上传
- 怎样分析复杂度
- iOS 自定义设置UITabBar 角标 badgeView 的背景色
- 二分图最大匹配专题
- 笔记
- 常用正则表达式大全!(例如:匹配中文、匹配html)
- NGUI常用参数详细说明
- Linux shell编程之sed命令三
- 最大上升子序列
- vi常用操作
- 物联网大数据平台软件开发架构案例解析