iOS 中的BadgeView(推送消息的那个圆形图标)
2014-11-06 09:58
232 查看
1.直接用系统的
想要在任意一个位置加图标 思路为先从系统的tabbar里把badgeView取出来 然后再放到其他view上
- (UIView *)showBadgeValue:(NSString *)strBadgeValue
{
UITabBar *tabBar = [[UITabBar
alloc] initWithFrame:CGRectMake(0,
0, 320,
50)];
UITabBarItem *item = [[UITabBarItem
alloc] initWithTitle:@""
image:nil
tag:0];
item.badgeValue = strBadgeValue;
NSArray *array = [[NSArray
alloc] initWithObjects:item,
nil];
tabBar.items = array;
//寻找
for (UIView *viewTab
in tabBar.subviews) {
for (UIView *subview
in viewTab.subviews) {
NSString *strClassName = [NSString
stringWithUTF8String:object_getClassName(subview)];
if ([strClassName
isEqualToString:@"UITabBarButtonBadge"] ||
[strClassName
isEqualToString:@"_UIBadgeView"]) {
//
[self.view
addSubview:subview];
subview.frame =
CGRectMake(self.view.frame.size.width-subview.frame.size.width,
0,
subview.frame.size.width, subview.frame.size.height);
return subview;
}
}
}
return nil;
}
//从原视图上移除
- (void)removeBadgeValue
{
//
for (UIView *subview
in self.view.subviews) {
NSString *strClassName = [NSString
stringWithUTF8String:object_getClassName(subview)];
if ([strClassName
isEqualToString:@"UITabBarButtonBadge"] ||
[strClassName
isEqualToString:@"_UIBadgeView"]) {
[subview removeFromSuperview];
break;
}
}
}
2.第三方JBBadgeView https://github.com/JaviSoto/JSBadgeView
想要在任意一个位置加图标 思路为先从系统的tabbar里把badgeView取出来 然后再放到其他view上
- (UIView *)showBadgeValue:(NSString *)strBadgeValue
{
UITabBar *tabBar = [[UITabBar
alloc] initWithFrame:CGRectMake(0,
0, 320,
50)];
UITabBarItem *item = [[UITabBarItem
alloc] initWithTitle:@""
image:nil
tag:0];
item.badgeValue = strBadgeValue;
NSArray *array = [[NSArray
alloc] initWithObjects:item,
nil];
tabBar.items = array;
//寻找
for (UIView *viewTab
in tabBar.subviews) {
for (UIView *subview
in viewTab.subviews) {
NSString *strClassName = [NSString
stringWithUTF8String:object_getClassName(subview)];
if ([strClassName
isEqualToString:@"UITabBarButtonBadge"] ||
[strClassName
isEqualToString:@"_UIBadgeView"]) {
//
[self.view
addSubview:subview];
subview.frame =
CGRectMake(self.view.frame.size.width-subview.frame.size.width,
0,
subview.frame.size.width, subview.frame.size.height);
return subview;
}
}
}
return nil;
}
//从原视图上移除
- (void)removeBadgeValue
{
//
for (UIView *subview
in self.view.subviews) {
NSString *strClassName = [NSString
stringWithUTF8String:object_getClassName(subview)];
if ([strClassName
isEqualToString:@"UITabBarButtonBadge"] ||
[strClassName
isEqualToString:@"_UIBadgeView"]) {
[subview removeFromSuperview];
break;
}
}
}
2.第三方JBBadgeView https://github.com/JaviSoto/JSBadgeView
相关文章推荐
- 【iOS学习笔记】IOS开发中设置applicationIconBadgeNumber和消息推送
- iOS 消息推送 点击app图标 app icon如何获取推送信息 leanCloud 点击app图标 获得推送消息
- iOS设置applicationIconBadgeNumber和消息推送
- iOS 【iOS 8 中设置applicationIconBadgeNumber(app新消息数字标识)和消息推送】
- IOS开发—IOS 8 中设置applicationIconBadgeNumber和消息推送
- IOS开发—IOS 8 中设置applicationIconBadgeNumber和消息推送
- IOS推送消息怎么实现icon图标的数字累加
- IOS图标消息推送在不同ios版本中的推送相关
- IOS 9 中设置applicationIconBadgeNumber和消息推送
- IOS 8 以上版本 设置applicationIconBadgeNumber和消息推送
- IOS推送消息怎么实现icon图标的数字累加
- 【转】IOS开发—IOS 8 中设置applicationIconBadgeNumber和消息推送
- iOS如何显示桌面应用图标上的推送消息数(大神勿进)
- IOS开发—IOS 8 中设置applicationIconBadgeNumber和消息推送
- IOS推送消息怎么实现icon图标的数字累加
- IOS 推送消息 php做推送服务端
- iOS消息推送机制的实现
- iOS开发如何实现消息推送机制
- iOS开发如何实现消息推送机制
- iOS开发如何实现消息推送机制