zoukankan      html  css  js  c++  java
  • 【源码】iOS消息通知 小红点&自定义小红点&应用图标添加提示

       //添加消息通知 小红点iOS自带

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

        UITabBarItem *personCenterTabBarItem = [tabBarItems objectAtIndex:2];

        personCenterTabBarItem.badgeValue = @"1";

        //自定义方法(还需完善)

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

        dotImage.backgroundColor = [UIColor clearColor];

        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.tabBar addSubview:dotImage];

        //应用图标添加提示

        UIUserNotificationSettings *settings = [UIUserNotificationSettings

                                                    settingsForTypes:UIUserNotificationTypeBadge categories:nil];

        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];

        [UIApplication sharedApplication].applicationIconBadgeNumber = 2;

    SVSettingsViewCtrl类中:

    1.在- (UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath方法中添加

     //第一次出现时添加

                SVProbeInfo *probeInfo = [SVProbeInfo sharedInstance];

                if (![probeInfo isFirstStart])

                {

                    if (indexPath.row == 0)

                    {

                    // 显示新功能指引

                    [self showNewView:cell];

                     //设置首次启动标志位

                    [probeInfo setFirstStart:YES];

                    }

                }

    2.添加方法:

    //添加新功能提示

    -(void)showNewView :(UITableViewCell *)cell{

        btn = [[UIButton alloc]init];

        // 按钮类型

        btn = [UIButton buttonWithType:UIButtonTypeCustom];

        // 按钮尺寸

        btn.frame = CGRectMake(FITWIDTH(200), cell.height *0.25, cell.height,cell.height*0.5);

        // 按钮背景颜色

        btn.backgroundColor = [UIColor redColor];

        //设置文字

        [btn setTitle:@"new" forState:UIControlStateNormal];

        // 按钮圆角

        btn.layer.cornerRadius = svCornerRadius (30

                                                 );

        // 设置居中

        btn.titleLabel.textAlignment = NSTextAlignmentCenter;

        // 按钮文字颜色和类型

        [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

        // 设置字体大小

        [btn.titleLabel setFont:[UIFont systemFontOfSize:pixelToFontsize (40)]];

        // 设置按钮默认情况下不可交互

        btn.enabled = NO;

        [cell addSubview:btn];

    }

    //隐藏新功能提示

    -(void)hideNewView{

        [btn removeFromSuperview];

    }

    3.在- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath中添加

            //第一次出现时添加

            SVProbeInfo *probeInfo = [SVProbeInfo sharedInstance];

            if (![probeInfo isFirstStart])

            {

                if (indexPath.row == 0)

                {

                    [self hideNewView];

                }

            }

  • 相关阅读:
    OneDay!——冲刺日志9(05-06)
    Hail_Hydra2—代码规范
    Hail_Hydra2—凡事预则立
    Alpha冲刺的问题总结
    Hail_Hydra2—冲刺日志集合
    Hail_Hydra2—总结随笔
    Hail_Hydra2—测试随笔
    Hail_Hydra2—冲刺日志(10)
    Hail_Hydra2—冲刺日志(9)
    Hail_Hydra2—冲刺日志(8)
  • 原文地址:https://www.cnblogs.com/wangbinios/p/5702082.html
Copyright © 2011-2022 走看看