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

系统方法:

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

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. Attach source code to a Netbeans Library Wrapper Module

    http://rubenlaguna.com/wp/2008/02/22/attach-source-code-to-a-netbeans-library-wrapper-module/ Attach ...

  2. MYSQL数据库性能调优之二:定位慢查询

    windows下开启慢查询: 第一步:先查看版本 第二步查看查询日志和慢查询配置 第三步:配置开启慢查询 在my.ini配置文件的[mysqld]选项下增加: slow_query_log=TRUE ...

  3. HDU 2147 kiki's game (简单博弈,找规律)

    kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/1000 K (Java/Others)Total ...

  4. 基于jQuery的视频和音频播放器jPlayer

    jPlayer见网络上资料很少,官方英文资料太坑爹TAT,于是就写一个手记给大家参考下.据我观察,jPlayer的原理主要是用到HTML5,在不支持HTML5的浏览器上使用SWF.做到全兼容,这一点很 ...

  5. 建表的sql

    1. 创建用户表 create table user( id int unsigned not null primary key auto_increment comment '自增id', user ...

  6. Quartz.NET 2.0 学习笔记(1) :Quartz.NET简介

    http://www.cnblogs.com/lzrabbit/archive/2012/04/13/2447609.html

  7. OC:内存管理、dealloc方法、copy知识点

    属性的声明:使⽤@property声明属性
 例如:@property NSString *name: 相当于@interface中声明了两个⽅法(setter.getter): 属性的实现:使⽤@s ...

  8. Oracle数据库定时任务配置和日志执行情况查询

    基础配置: /***************************************************************** * * 移动抵扣券快到期推送提醒 * 首次执行 : 2 ...

  9. HTML第七天学习笔记

    今天主要是学习如何使用JS,第一个就是先是使用JS输出"Hello world" <!doctype html> <html lang="en" ...

  10. PostgreSQL中的数组与Any

    建立表: CREATE TABLE sal_emp ( name text, pay_by_quarter integer[], schedule text[][] ); 插入数据: INSERT I ...