NSMenuItem A name that changes over time.

I would like to implement NSStatusItem where the name changes over time. My ultimate goal is to display a countdown timer in the menu bar next to the image I set. Maybe I'm wrong. But I already have a string of characters that constantly change over time, which is a timer. I am trying to understand how I can place this line next to the image that I set for the created menu box.

statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
[statusItem setTitle:"29:30"];

I tried several calls to the setTitle method, but they don't seem to work. Only the initial setTitle call works before the object is initialized. After that, nothing happens. I think I could free the NSStatusItem object and recreate it every time I want the timer to change, but that seems very inefficient. I'm not even sure if this will work.

I also looked at using the setToolTip method to display a timer countdown. But this is similar to the setTitle method. Once it is installed, you cannot change it until you release the NSStatusItem object and create a new one.

Any suggestions would be appreciated.

thank

Dave

+3
source share
2 answers

. -setTitle , , . , , . setTitle . , setTitle. .

statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
[statusItem setTitle:"29:30"];

Dave

+2

-setView:? , .

0

Source: https://habr.com/ru/post/1772835/


All Articles