How to Show Two Row of Text in a Menu Bar App in MAC Os

How to draw two lines of text in a NSView subclass ? (macOS system tray)

Doubt that it's what you are looking for, but this will put two lines of text in a status item:

import Cocoa

let app = NSApplication.shared
let statusItem = NSStatusBar.system.statusItem(withLength:-1)
statusItem.button?.font = NSFont(name:"Menlo Bold", size: 10.0)
statusItem.button!.title = "one\ntwo"
app.run()

It's still just one button and I don't see how you will separate the selection of each item. Perhaps a drop down menu would work better?

How can I get a two-row toolbar like in Mail.app and Xcode?

What I needed to do was call [NSToolbar setFullScreenAccessoryView:] on the view below my toolbar. This results in the behavior I was aiming for. See the NSToolbar documentation for this method.

How can I read the user selection for OS X menu bar in Xcode (Swift)

It appears that you are trying to invert menulet icon color for dark mode. By default OSX handles darkmode and inverts the image color, however you need to specifically add [image setTemplate:YES] to have this work for you if it already doesnt.

Objective-c:

self.statusItem = [[NSStatusBar systemStatusBar]     
statusItemWithLength:NSSquareStatusItemLength];
NSImage *image = [NSImage imageNamed:@"statusItemIcon"];
[image setTemplate:YES];
[self.statusItem setImage:image];

swift: (Originally answered by Zhi-Wei Cai at link below)

var isDark = false

func isDarkMode() {
// Swift2
// isDark = NSAppearance.currentAppearance().name.hasPrefix("NSAppearanceNameVibrantDark")

// Swift3+
isDark = NSAppearance.current.name.rawValue.hasPrefix("NSAppearanceNameVibrantDark")
}

override func drawRect(dirtyRect: NSRect) {
super.drawRect(dirtyRect)
isDarkMode()
// Now use "isDark" to determine the drawing colour.
if isDark {
// ...
} else {
// ...
}
}

This answer explains it in the detail: NSStatusItem change image for dark tint

How to get the Spotlight-like text input effect in menu bar?

If you're using xcode 4 , make a custom view in interface builder and add a textfield or anything you want to it. In IB also drag and drop a "Menu" from the objects library with as many items as you want in it. Then simply ctrl+click the menu item you want to make into the text field (In your case it would be the top one) and drag to the custom view and select "view". Now when you open the menu, instead of showing a menu item in that space, it shows whatever was in your custom view.

EDIT: As for your comment here's what you should do. Make your menu an outlet by opening the assistant editor view and ctrl+click from your menu to the header file that you want to use. now, simply make a method that will run whenever the menu will open, conveniently apple already made this, it's called menuWillOpen.

- (void)menuWillOpen: nameOfYourMenu{

[self performSelector:@selector(methodExecutedWhenMenuIsClicked) withObject:nil afterDelay:0.0 inModes:[NSArray arrayWithObject:NSRunLoopCommonModes]];

the delay at 0 will make it happen immediately, it must be done in the common modes run loop so that the menu will be updated even while it's open. Now just make the methodExecutedWhenMenuIsClicked and set it so the text field responds.

- (void)methodExecutedWhenMenuIsClicked{

[[yourTextfiled window] makeFirstResponder:yourTextField];


Related Topics



Leave a reply



Submit