IOS開發(fā)過程中的消息通知--小紅點
更新時間:2017年04月10日 11:31:22 作者:cx_wzp
本文主要介紹了IOS開發(fā)過程中的消息通知--小紅點的相關知識。大致分為兩種方法:系統(tǒng)方法和自定義方法。下面跟著小編一起來看下吧
大致分為兩種方法:系統(tǒng)方法和自定義方法
系統(tǒng)方法:
系統(tǒng)自帶的方法可以顯示具體的消息數(shù)量,這個就是蘋果設備常見的小紅點。實現(xiàn)思路如下:
NSArray *tabBarItems = self.navigationController.tabBarController.tabBar.items; UITabBarItem *personCenterTabBarItem = [tabBarItems objectAtIndex:3]; personCenterTabBarItem.badgeValue = @"2";//顯示消息條數(shù)為 2
效果如下圖所示:

自定義方法:
自己將小紅點圖標放在想要顯示的位置,控制UIImageView的hidden屬性即可。實現(xiàn)思路如下:
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的桌面應用圖標上的消息提示,實現(xiàn)思路如下:
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 中NSUserDefaults讀取和寫入自定義對象的實現(xiàn)方法
這篇文章主要介紹了IOS 中NSUserDefaults讀取和寫入自定義對象的實現(xiàn)方法的相關資料,希望通過本文大家能夠理解掌握這部分內容,需要的朋友可以參考下2017-09-09

