zoukankan      html  css  js  c++  java
  • 小红点

    一.系统自带

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

        

     

     

  • 相关阅读:
    通过Xshell连接CentOS虚拟机
    Linux学习笔记
    JAVA学习摘要
    4k 对齐,你准备好了吗?
    图片种子制作方法,利用图片上传附件
    利用京东服务免费打造属于自己的网站
    PE制作实录 —— 补充说明
    PE制作实录 —— 定义我的 PE 工具箱
    浏览器 — 各项基准测试
    Windows 8.1 归档 —— Step 3 软件的选择与安装
  • 原文地址:https://www.cnblogs.com/daxueshan/p/5849339.html
Copyright © 2011-2022 走看看