【源碼】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];

            }

        }

 


免責聲明!

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



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