0

This count in the rightside of messenger name

I want to display the unread messages count (Refer: Fig) as badgelabel as similar to [[NSApp dockTile] setBadgeLabel:@""]; over the image icons.

Can anybody tell me the proper way to do that using Objective-C?

Marek H
  • 5,173
  • 3
  • 31
  • 42
Jeba Moses
  • 809
  • 8
  • 25
  • Are you just trying to add a badge to an image? Why don't you just create a view that looks like a badge and has a number in it and add that as a subview? – Lucas Derraugh Nov 15 '16 at 07:30
  • That is cool idea @LucasDerraugh, The problem is digits in the number will be dynamic, it may be one, two or three digit at different situations according to the unread message count. if i add the NSView its size will not dynamic. – Jeba Moses Nov 15 '16 at 09:25
  • It can be. You just have to setup AutoLayout to center on the position you want and then have the textfield (what holds the text) push the contents of the view to grow as the text becomes longer. – Lucas Derraugh Nov 15 '16 at 09:40
  • I directly tried to create Circle Shaped label(NSTextField) using the following code: '[gradient drawInBezierPath:[NSBezierPath bezierPathWithRoundedRect:blackOutlineFrame xRadius:10 yRadius:10] angle:90];' But the problem, text is not visible, even though i use "setString" – Jeba Moses Nov 15 '16 at 09:51
  • 1
    I'd recommend making a custom NSView that has an NSTextField subview (make it a standard label). Add the constraints on the NSTextField so that it pushes out the containing view. There are ways to achieve this without explicit constraints, but they probably make it easier. – Lucas Derraugh Nov 15 '16 at 10:08
  • ok thank you @LucasDerraugh, i will try these hacks and let you know.. – Jeba Moses Nov 15 '16 at 10:18
  • 1
    hi @LucasDerraugh i have implemented your idea(custom NSView). It worked well for me.. Thanks lot man. – Jeba Moses Dec 09 '16 at 10:12
  • NSimage has a private method that does the image [NSImage _emblemForCount:3]; – Marek H Mar 08 '19 at 10:40

0 Answers0