IOS 开发过程中的 消息通知 小红点
2016-05-18 10:30
691 查看
大致分为两种方法:系统方法和自定义方法
系统方法:
系统自带的方法可以显示具体的消息数量,这个就是苹果设备常见的小红点。实现思路如下:
NSArray *tabBarItems = self.navigationController.tabBarController.tabBar.items;
UITabBarItem *personCenterTabBarItem = [tabBarItems objectAtIndex:3];
personCenterTabBarItem.badgeValue = @"2";//显示消息条数为 2
效果如下图所示:
自定义方法:
自己将小红点图标放在想要显示的位置,控制UIImageView的hidden属性即可。实现思路如下:
UIImageView *dotImage = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"red_point_small"]];
dotImage.backgroundColor = [UIColorclearColor];
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.tabBaraddSubview:dotImage];
效果如下图所示:
上面提到的方法,基本上可以放在ViewController的任何位置,不过还有一种情况做不到,就是App的桌面应用图标上的消息提示。
————————————————————————————————————
App的桌面应用图标上的消息提示,实现思路如下:
if ([[XWGlobalHelpersystemVersion]
intValue] >7.99 && [[XWGlobalHelpersystemVersion]
intValue] <9.001) {
//IOS8 需要 设置
UIUserNotificationSettings *settings = [UIUserNotificationSettingssettingsForTypes:UIUserNotificationTypeBadgecategories:nil];
[[UIApplicationsharedApplication]
registerUserNotificationSettings:settings];
}
[UIApplicationsharedApplication].applicationIconBadgeNumber
=3;
系统方法:
系统自带的方法可以显示具体的消息数量,这个就是苹果设备常见的小红点。实现思路如下:
NSArray *tabBarItems = self.navigationController.tabBarController.tabBar.items;
UITabBarItem *personCenterTabBarItem = [tabBarItems objectAtIndex:3];
personCenterTabBarItem.badgeValue = @"2";//显示消息条数为 2
效果如下图所示:
自定义方法:
自己将小红点图标放在想要显示的位置,控制UIImageView的hidden属性即可。实现思路如下:
UIImageView *dotImage = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"red_point_small"]];
dotImage.backgroundColor = [UIColorclearColor];
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.tabBaraddSubview:dotImage];
效果如下图所示:
上面提到的方法,基本上可以放在ViewController的任何位置,不过还有一种情况做不到,就是App的桌面应用图标上的消息提示。
————————————————————————————————————
App的桌面应用图标上的消息提示,实现思路如下:
if ([[XWGlobalHelpersystemVersion]
intValue] >7.99 && [[XWGlobalHelpersystemVersion]
intValue] <9.001) {
//IOS8 需要 设置
UIUserNotificationSettings *settings = [UIUserNotificationSettingssettingsForTypes:UIUserNotificationTypeBadgecategories:nil];
[[UIApplicationsharedApplication]
registerUserNotificationSettings:settings];
}
[UIApplicationsharedApplication].applicationIconBadgeNumber
=3;
相关文章推荐
- IOS NSDate日期操作总结
- iOS--(转)常用正则表达式
- iOS--(转)WiFi传输数据
- iOS--(转)WiFi传输数据
- iOS开发中Pch文件的使用
- iOS之修改项目BUG之旅--(六)
- 浅析.tbd与.dylib
- IOS多线程编程技术NSThread、Cocoa NSOperation、CGD 三者使用详解
- iOS MVC设计模式
- iOS tableView编辑删除(单选 多选)
- iOS崩溃 捕获异常处理
- iOS 当前应用所占内存和设备可用内存
- iOS后台运行定时器
- iOS之如何自适应TableViewCell的高度
- 监听用户进入,离开某个区域,需要请求获取用户的位置,如果想在后台也能监听,需要配置ios9后台监听
- iOS 后台定位审核被拒How to clarify the purpose of its use in the location modal?
- iOS学习笔记36-Masonry自动布局
- iOS深复制和浅复制
- iOS深入学习(Block全面分析)
- iOS开发——响应链(Responder Chain)的深入理解和代码示例