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