【源码】iOS消息通知 小红点&自定义小红点&应用图标添加提示
//添加消息通知 小红点iOS自带
NSArray *tabBarItems = self.navigationController.tabBarController.tabBar.items;
UITabBarItem *personCenterTabBarItem = [tabBarItems objectAtIndex:2];
personCenterTabBarItem.badgeValue = @"1";
//自定义方法(还需完善)
UIImageView *dotImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ic_speed_check"]];
dotImage.backgroundColor = [UIColor clearColor];
CGRect tabFrame =self.navigationController.tabBarController.tabBar.frame;
CGFloat x =ceilf(0.9 * tabFrame.size.width);
CGFloat y =ceilf(0.1 * tabFrame.size.height);
dotImage.frame =CGRectMake(x, y, 8,8);
[self.navigationController.tabBarController.tabBar addSubview:dotImage];
//应用图标添加提示
UIUserNotificationSettings *settings = [UIUserNotificationSettings
settingsForTypes:UIUserNotificationTypeBadge categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[UIApplication sharedApplication].applicationIconBadgeNumber = 2;
SVSettingsViewCtrl类中:
1.在- (UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath方法中添加
//第一次出现时添加
SVProbeInfo *probeInfo = [SVProbeInfo sharedInstance];
if (![probeInfo isFirstStart])
{
if (indexPath.row == 0)
{
// 显示新功能指引
[self showNewView:cell];
//设置首次启动标志位
[probeInfo setFirstStart:YES];
}
}
2.添加方法:
//添加新功能提示
-(void)showNewView :(UITableViewCell *)cell{
btn = [[UIButton alloc]init];
// 按钮类型
btn = [UIButton buttonWithType:UIButtonTypeCustom];
// 按钮尺寸
btn.frame = CGRectMake(FITWIDTH(200), cell.height *0.25, cell.height,cell.height*0.5);
// 按钮背景颜色
btn.backgroundColor = [UIColor redColor];
//设置文字
[btn setTitle:@"new" forState:UIControlStateNormal];
// 按钮圆角
btn.layer.cornerRadius = svCornerRadius (30
);
// 设置居中
btn.titleLabel.textAlignment = NSTextAlignmentCenter;
// 按钮文字颜色和类型
[btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
// 设置字体大小
[btn.titleLabel setFont:[UIFont systemFontOfSize:pixelToFontsize (40)]];
// 设置按钮默认情况下不可交互
btn.enabled = NO;
[cell addSubview:btn];
}
//隐藏新功能提示
-(void)hideNewView{
[btn removeFromSuperview];
}
3.在- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath中添加
//第一次出现时添加
SVProbeInfo *probeInfo = [SVProbeInfo sharedInstance];
if (![probeInfo isFirstStart])
{
if (indexPath.row == 0)
{
[self hideNewView];
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端