如何在ios的收件箱中显示消息计数

时间:2014-10-31 04:44:28

标签: ios objective-c swift

我正在制作一个收件箱模块,我想在标签上显示消息计数。数据来自服务器。因此,如果我们有30条消息,标签将显示30条消息。怎么做?推送通知概念会在这里使用吗?

1 个答案:

答案 0 :(得分:0)

通过编程方式或使用UILablel创建一个IBOutlet并将frame设置为您想要应用的位置,最后设置为

#import <QuartzCore/QuartzCore.h>


UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(50, 50, 30, 30)]; //change the frame size as you need
label.layer.borderColor = [UIColor whiteColor].CGColor;
label.layer.borderWidth = 2.0;
label.layer.cornerRadius = label.bounds.size.height / 2;
label.TextAlignment=NSTextAlignmentCenter;
label.layer.masksToBounds = YES;
label.text=[NSString stringWithFormat:@"%d",yourarrayname.count];  // here add your message array name
label.textColor=[UIColor whiteColor];
label.backgroundColor=[UIColor redColor];
[self.view addSubview:label];

<强>夫特

let label: UILabel = UILabel(frame: CGRectMake(50, 50, 30, 30))//change the frame size as you need
label.layer.borderColor = UIColor.whiteColor().CGColor
label.layer.borderWidth = 2.0
label.layer.cornerRadius = label.bounds.size.height / 2
label.TextAlignment = .Center
label.layer.masksToBounds = true
label.text = "\(yourarrayname.count)" // here add your message array name
label.textColor = UIColor.whiteColor()
label.backgroundColor = UIColor.redColor()
self.view!.addSubview(label)

输出

enter image description here