大致分为两种方法:系统方法和自定义方法
系统方法:
系统自带的方法可以显示具体的消息数量,这个就是苹果设备常见的小红点。实现思路如下:
?| 1 2 3 |
nsarray *tabbaritems = self.navigationcontroller.tabbarcontroller.tabbar.items;
uitabbaritem *personcentertabbaritem = [tabbaritems objectatindex:3];
personcentertabbaritem.badgevalue = @"2";//显示消息条数为 2
|
效果如下图所示:

自定义方法:
自己将小红点图标放在想要显示的位置,控制uiimageview的hidden属性即可。实现思路如下:
?| 1 2 3 4 5 6 7 |
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的桌面应用图标上的消息提示,实现思路如下:
?| 1 2 3 4 5 6 7 8 |
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;
|
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持服务器之家!
原文链接:http://blog.csdn.net/cx_wzp/article/details/49099049








发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。