IOS開發(fā)過程中的消息通知--小紅點
大致分為兩種方法:系統(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適配https證書問題(AFNetworking3.0為例)
本篇文章主要介紹了iOS適配https問題(AFNetworking3.0為例)。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02
iOS開發(fā)存儲應用程序Info.plist知識全面詳解
這篇文章主要為大家介紹了iOS開發(fā)存儲應用程序Info.plist知識全面詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-06-06

