Mishal Awan Mishal Awan - 5 months ago 45
iOS Question

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?

Answer

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