大致分为两种方法:系统方法和自定义方法

系统方法:

系统自带的方法可以显示具体的消息数量,这个就是苹果设备常见的小红点。实现思路如下:

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 ([[XWGlobalHelper systemVersion] intValue] > 7.99 && [[XWGlobalHelper systemVersion] intValue] <9.001) {

//IOS8 需要 设置

UIUserNotificationSettings *settings = [UIUserNotificationSettings
settingsForTypes:UIUserNotificationTypeBadge categories:nil];

[[UIApplication sharedApplication] registerUserNotificationSettings:settings];

}

[UIApplication sharedApplication].applicationIconBadgeNumber = 3;

IOS 开发过程中的 消息通知 小红点的更多相关文章

  1. 038改变状态栏的颜色(扩展知识:关于iOS不同版本的消息通知知识)

    效果如下: ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController @e ...

  2. iOS开发过程中使用Core Data应避免的十个错误

    原文出处: informit   译文出处:cocoachina Core Data是苹果针对Mac和iOS平台开发的一个框架,主要用来储存数据.对很多开发者来说,Core Data比较容易入手,但很 ...

  3. Android中的消息通知(NotificationManager和Notification)

    下面来谈谈notification,这个notification一般用在电话,短 信,邮件,闹钟铃声,在手机的状态栏上就会出现一个小图标,提示用户处理这个通知,这时手从上方滑动状态栏就可以展开并处理这 ...

  4. iOS开发中UILocalNotification本地通知实现简单的提醒功能

    这段时间项目要求做一个类似的闹钟提醒功能,对通知不太熟悉的我,决定先用到xcode自带的本地通知试试,最终成功的实现了功能,特整理分享下. 它的表现特点: app关闭的时候也能接收和显示通知. app ...

  5. IOS开发中如何使用通知NSNotification传值

    通知 是在跳转控制器之间常用的传值代理方式,除了代理模式,通知更方便.便捷,一个简单的Demo实现通知的跳转传值. 输入所要发送的信息 ,同时将label的值通过button方法调用传递, - (IB ...

  6. 在iOS开发过程中你遇到这个问题了么?

    1.问题:加载UIWebView底部有黑色边框问题. 设置UIWebView opaque为NO,然后设置其背景色为clearColor. 2.问题:iPhone真机输出[UIScreen mainS ...

  7. ios开发过程中描述文件(provisioning profile)过期导致ios无法正常安装的处理办法

    1.登录开发者中心,重新编辑描述文件,获得最新的描述文件.(如果对应的P12文件也过期,需要同时下载最新的p12文件).----该步骤需要有权限的人才能操作. 2.下载最新的描述文件和p12文件(如果 ...

  8. iOS开发过程中常见错误问题及解决方案

    错误原因:ld: x duplicate symbol for architecture x86_64 clang: error: linker command failed with exit co ...

  9. iOS开发过程中 xcode文件与Finder中文件保持一致 + 支付宝集成出错

    目录 环境 前言 1.使用 Gem 安装 synx 2.直接在终端 Terminal 中开始使用 3.在使用的时候还可以加参数来实现不同的功能 4.解决项目中出现的一些 error 环境 OS X 1 ...

随机推荐

  1. LINQ标准查询操作符(四) —AsEnumerable,Cast,OfType,ToArray,ToDictionary,ToList,ToLookup,First,Last,ElementAt

    十.转换操作符 转换操作符是用来实现将输入对象的类型转变为序列的功能.名称以“As”开头的转换方法可更改源集合的静态类型但不枚举(延迟加载)此源集合.名称以“To”开头的方法可枚举(即时加载)源集合并 ...

  2. DataGrid参数

    1.3.2 data-options="singleSelect:true,collapsible:false,url:'/datagrid/getbasic'"    参数 类型 ...

  3. 触控发布《Cocos开发者平台白皮书》

    Cocos 2014 开发者大会(秋季)组委会今天正式发布了<Cocos开发者平台白皮书>,GameRes游资网得到Cocos官方授权发布该白皮书电子版. 白皮书主要内容包括对行业的趋势解 ...

  4. JDBC 常用驱动类及url格式

    1. oracle <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</ ...

  5. iOS设置导航栏样式(UINavigationController)

    //设置导航栏baritem和返回baiitem样式 UIBarButtonItem *barItem = [UIBarButtonItem appearance]; //去掉返回按钮上的字 [bar ...

  6. UITextFiled,UIButton,UIImageView交互相互之间的事件拦截

    UIButton右上方添加一个笑button如: UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];    button.f ...

  7. jedis提供的功能

    Sorting(排序) Connection handling(连接池) Commands operating on any kind of values Commands operating on ...

  8. Ucenter后台登陆 验证码CCCC的解决方法 无法登录解决办法

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html 内部邀请码:C8E245J (不写邀请码,没有现金送) 国 ...

  9. AllocateHwnd is not Thread-Safe

    http://www.thedelphigeek.com/2007/06/allocatehwnd-is-not-thread-safe.html http://gp.17slon.com/gp/fi ...

  10. 初步认识pg_control文件之一

    这个据说是PostgreSQL的control file. 到底如何呢,先看看改名后如何,把pg_control文件改名,然后启动 Postgres,运行时得到信息: [postgres@pg101 ...