tabbar添加小紅點


系統方法:

系統自帶的方法可以顯示具體的消息數量,這個就是蘋果設備常見的小紅點。實現思路如下:

 

NSArray *tabBarItems = self.navigationController.tabBarController.tabBar.items;

UITabBarItem *personCenterTabBarItem = [tabBarItems objectAtIndex:3];

personCenterTabBarItem.badgeValue = @"2";//顯示消息條數為 2

 

自定義方法:

自己將小紅點圖標放在想要顯示的位置,控制UIImageView的hidden屬性即可。實現思路如下:

 

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];

 

 

App的桌面應用圖標上的消息提示,實現思路如下:

        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;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM