欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

小红点

发布时间:2025/3/18 47 豆豆
生活随笔 收集整理的这篇文章主要介绍了 小红点 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

一.系统自带

 [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+" 

二.自定义

//    自定义方法:

//    自己将小红点图标放在想要显示的位置,控制UIImageViewhidden属性即可。实现思路如下:

    // 创建一个UIImageView,存放小红点图片

    UIImageView *dotImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"red_point_small"]];

    dotImage.backgroundColor = [UIColor redColor];

    // 获取tabbarItameframe

    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

总结

以上是生活随笔为你收集整理的小红点的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。