小红点
一.系統自帶
?[super viewDidLoad];
? ? // Do any additional setup after loading the view, typically from a nib.
? ? self.view.backgroundColor = [UIColor whiteColor];
? ? self.navigationItem.title = @"首頁";
? ? UITabBarItem *item = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:1];
? ? self.tabBarItem = item;
?? ?
//? ? NSArray *tabBarItems = self.navigationController.tabBarController.tabBar.items;
//? ? // 獲取到需要展示消息的tabbarItem,屬性badgeValue(標記個數)就是消息的條數
//? ? UITabBarItem *personCenterTabBarItem = [tabBarItems objectAtIndex:3];
//? ? personCenterTabBarItem.badgeValue = @"2";//顯示消息條數為 2
? ? item.badgeValue = @"99+";??
二.自定義
//? ? 自定義方法:
//? ? 自己將小紅點圖標放在想要顯示的位置,控制UIImageView的hidden屬性即可。實現思路如下:
? ? // 創建一個UIImageView,存放小紅點圖片
? ? UIImageView *dotImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"red_point_small"]];
? ? dotImage.backgroundColor = [UIColor redColor];
? ? // 獲取tabbarItame的frame
? ? CGRect tabFrame =self.navigationController.tabBarController.tabBar.frame;
? ? CGFloat x =ceilf(0.5 * tabFrame.size.width);
? ? CGFloat y =ceilf(0.1 * tabFrame.size.height);
? ? // 設置小紅點圖標的frame
? ? dotImage.frame =CGRectMake(x, y, 8,8);
? ? // 將小紅點imageView添加到tabbar上面
? ? [self.navigationController.tabBarController.tabBar addSubview:dotImage];
?
三.桌面icon圖標紅點
//獲取用戶授權
? ? if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
? ? ? ? UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil];
? ? ? ? [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
? ? }
? ? //注冊消息推送
? ? if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
? ? ? ? UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge categories:nil];
? ? ? ? [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
? ? ? ? [[UIApplication sharedApplication] registerForRemoteNotifications];
? ? }
? ? //設置推送消息個數
? ? [[UIApplication sharedApplication] setApplicationIconBadgeNumber:10];
? ??
?
?
轉載于:https://www.cnblogs.com/daxueshan/p/5849339.html
總結
- 上一篇: Android UI控件----Expa
- 下一篇: Linux系统搭建Red5服务器