
在应用开发中经常遇到在tabbar的某个控制器中界面会有新消息的提示,需要在该tabBar上显示标记点,以便让用户了解到你有新消息,提升用户体验。如QQ中动态提示
一 .首先创建个分类(类别) UITabBarController+Badge
在该分类的.h文件给出三个方法:
- (void)showBadgeOnItemIndex:(int)index;//显示提示小红点标记
- (void)hideBadgeOnItemIndex:(int)index;//隐藏小红点标记
- (void)removeBadgeOnItemIndex:(int)index;//移除小红点标记
在分类的.m文件中实现这三个方法:
#define TabbarItemNums 4.0 //tabbar的数量
- (void)showBadgeOnItemIndex:(int)index{
//移除之前的小红点
[self removeBadgeOnItemIndex:index];
//新建小红点
UIView *badgeView = [[UIView alloc]init];
badgeView.tag = 800 + index;
badgeView.layer.cornerRadius = 5;
badgeView.backgroundColor = [UIColor redColor];
CGRect tabFram

本文介绍了一个UITabBarController的分类,用于在iOS应用的TabBar上显示或隐藏新消息提示的小红点,以增强用户体验。通过简单的方法调用即可实现标记点的展示与移除。
最低0.47元/天 解锁文章
298

被折叠的 条评论
为什么被折叠?



