iOS技巧之Notification,BadgeView
作者:佚名
OS可方便的在應用圖標上添加badgeView,有時候在應用程序內,我們也需要添加像圖標上的公色數字的提醒,本文主要內容:1、iOS提醒三種方式,自帶的圖標上的badge,alert,notification;2、自定義badgeView
Tips:自定義badgeView需要此類庫,不能使用ARC---badgeView封裝類庫下載 115網盤禮包碼:5lb7f4o6
自定義效果
一、iOS提醒三種方式,自帶的圖標上的badge,alert,notification
在需要添加通知處,添加
- UILocalNotification *notification=[[UILocalNotification alloc]init];
- notification.repeatInterval=0;//設置提醒重復的次數
- notification.timeZone=[NSTimeZone defaultTimeZone];//設置時區
- //設置badge
- notification.applicationIconBadgeNumber=14;//設置number的值
- notification.soundName=UILocalNotificationDefaultSoundName;//設置通知聲音
- // 設置Alert
- notification.alertAction=@"打開";
- notification.alertBody=@"提醒";
- notification.hasAction=YES;
- [[UIApplication sharedApplication]scheduleLocalNotification:notification];
二、自定義badgeView
1、將下載的JSBadgeView解壓縮后添加到工程中,添加QuartzCore.framework
2、假設要在頁面中的button上添加一個Badge,在頁面上添加一個button,創建映射
- @property (retain, nonatomic) IBOutlet UIButton *button;
在需要添加badge處添加代碼
- //此處alignment有九種狀態可設置,一般放在右上角
- JSBadgeView *badgeView = [[JSBadgeView alloc ] initWithParentView:self.button alignment:JSBadgeViewAlignmentTopRight];
- // 設置badgeView中的text值,不一定是數字
- badgeView.badgeText = @"12";
- //還可設置badgeView的text字體,圓圈的顏色,陰影顏色等,參照JSBadgeView.h中的屬性進行自定義
- [self.button addSubview:badgeView];
- [self.view sendSubviewToBack:self.button];
責任編輯:閆佳明
來源:
oschina