当前位置: 移动技术网 > IT编程>移动开发>IOS > IOS开发过程中的消息通知--小红点

IOS开发过程中的消息通知--小红点

2019年07月24日  | 移动技术网IT编程  | 我要评论

昆明女恐怖分子照片,逢魔时刻遇见你,曾经心痛 狼牙

大致分为两种方法:系统方法和自定义方法

系统方法:

系统自带的方法可以显示具体的消息数量,这个就是苹果设备常见的小红点。实现思路如下:

nsarray *tabbaritems = self.navigationcontroller.tabbarcontroller.tabbar.items;
uitabbaritem *personcentertabbaritem = [tabbaritems objectatindex:3];
personcentertabbaritem.badgevalue = @"2";//显示消息条数为 2

效果如下图所示:

自定义方法:

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

uiimageview *dotimage = [[uiimageviewalloc] initwithimage:[uiimageimagenamed:@"red_point_small"]];
    dotimage.backgroundcolor = [uicolorclearcolor];
    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.tabbaraddsubview:dotimage];

效果如下图所示:

上面提到的方法,基本上可以放在viewcontroller的任何位置,不过还有一种情况做不到,就是app的桌面应用图标上的消息提示。

app的桌面应用图标上的消息提示,实现思路如下:

    if ([[xwglobalhelper systemversion] intvalue] > 7.99 && [[xwglobalhelper systemversion] intvalue] < 9.001) {
      
//ios8 需要 设置
uiusernotificationsettings *settings = [uiusernotificationsettings
settingsfortypes:uiusernotificationtypebadge categories:nil];
      [[uiapplication sharedapplication] registerusernotificationsettings:settings];
    }
    [uiapplication sharedapplication].applicationiconbadgenumber = 3;

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持移动技术网!

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网