Mishal Awan
Mishal Awan

Reputation: 724

How to Show count of Message in the inbox in ios

I am making an inbox module i want to show message count on a label. data is coming from server. so if we have 30 messages the label will show 30 messages. how it can be done? do push notification concept will use here or something else?

Upvotes: 2

Views: 931

Answers (1)

Anbu.Karthik
Anbu.Karthik

Reputation: 82769

create the one UILablel via programmatically or using IBOutlet and set the frame where u want to apply, finally set like

#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];

Swift

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)

the output is

enter image description here

Upvotes: 1

Related Questions