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

        

     

     

  • 相关阅读:
    php 快速fork出指定个子进程
    批量 kill mysql 中运行时间长的sql
    socket 发送发送HTTP请求
    Qt学习笔记常用容器
    Qt学习笔记 TableWidget使用说明和增删改操作的实现
    Qt学习笔记 线程(一)
    Qt学习笔记 QMessageBox
    Qt 学习笔记 TreeWidget 增删改
    Qt Creator 常用快捷键
    Qt学习笔记 ListWidget的增删改
  • 原文地址:https://www.cnblogs.com/daxueshan/p/5849339.html
Copyright © 2011-2022 走看看