iOS技巧之Notification,BadgeView

移动开发 iOS
OS可方便的在应用图标上添加badgeView,有时候在应用程序内,我们也需要添加像图标上的公色数字的提醒,本文主要内容:1、iOS提醒三种方式,自带的图标上的badge,alert,notification;2、自定义badgeView

Tips:自定义badgeView需要此类库,不能使用ARC---badgeView封装类库下载 115网盘礼包码:5lb7f4o6

自定义效果

一、iOS提醒三种方式,自带的图标上的badge,alert,notification

在需要添加通知处,添加

  1. UILocalNotification *notification=[[UILocalNotification alloc]init]; 
  2.     notification.repeatInterval=0;//设置提醒重复的次数 
  3.     notification.timeZone=[NSTimeZone defaultTimeZone];//设置时区 
  4.     //设置badge 
  5.     notification.applicationIconBadgeNumber=14;//设置number的值 
  6. notification.soundName=UILocalNotificationDefaultSoundName;//设置通知声音   
  7.     // 设置Alert 
  8.     notification.alertAction=@"打开"
  9.     notification.alertBody=@"提醒"
  10.     notification.hasAction=YES; 
  11.      [[UIApplication sharedApplication]scheduleLocalNotification:notification]; 

二、自定义badgeView

1、将下载的JSBadgeView解压缩后添加到工程中,添加QuartzCore.framework

2、假设要在页面中的button上添加一个Badge,在页面上添加一个button,创建映射

  1. @property (retain, nonatomic) IBOutlet UIButton *button; 

在需要添加badge处添加代码

  1. //此处alignment有九种状态可设置,一般放在右上角 
  2.     JSBadgeView *badgeView  = [[JSBadgeView alloc ] initWithParentView:self.button alignment:JSBadgeViewAlignmentTopRight]; 
  3.     // 设置badgeView中的text值,不一定是数字  
  4.     badgeView.badgeText = @"12"
  5.     //还可设置badgeView的text字体,圆圈的颜色,阴影颜色等,参照JSBadgeView.h中的属性进行自定义 
  6.     [self.button addSubview:badgeView]; 
  7.     [self.view sendSubviewToBack:self.button]; 
责任编辑:闫佳明 来源: oschina
相关推荐

2013-03-25 15:06:26

iOS通信模式

2015-07-08 09:56:25

Notificatio多线程

2013-04-11 16:08:50

iOS开发技巧积累

2014-08-04 17:46:15

NavBarTarBar

2013-05-17 10:54:37

iOS开发iOS SDK调试技巧

2017-04-10 18:34:16

AndroidNotificatio

2010-08-01 15:16:41

Android

2011-12-22 10:33:39

PhoneGap APNotificatio

2018-10-16 15:08:20

屏幕图像对象

2011-07-25 15:56:45

组策略

2011-07-01 16:05:22

SEO

2011-07-25 18:07:29

iPhone Push Notificati

2010-08-10 12:55:42

思科IOS备份恢复

2013-01-16 08:56:53

iOS故障排除指南

2009-02-26 09:59:00

IOS软件思科路由器

2011-07-11 15:26:49

性能优化算法

2014-06-09 14:18:24

2015-08-27 11:16:14

ios开发技巧

2010-08-05 14:16:37

路由器配置

2014-07-23 13:17:53

iOSUITextField
点赞
收藏

51CTO技术栈公众号