I was just wondering how to get the height of the apple menubar, in pixels (the one always on top)
(My screen size is 1200 x 800) i was wondering what it would be excluding the menubar.
I was just wondering how to get the height of the apple menubar, in pixels (the one always on top)
(My screen size is 1200 x 800) i was wondering what it would be excluding the menubar.
Programmatically (as this is SO, I was looking for a programmatical answer and google sent me here) you can get this by using:
CGFloat menuBarHeight = [[[NSApplication sharedApplication] mainMenu] menuBarHeight];
or as a graphic designer I know would say: 0.8cm ;)
As per @Ross's answer:
NSApplication.sharedApplication().mainMenu?.menuBarHeight
Unfortunately, this will return nil
before the app finishes launching (because the mainMenu
will be nil
). If you need this value earlier than that (and you don't want to guess it for the future OS releases), you can calculate it like so:
if let screen = NSScreen.mainScreen() {
let menuBarHeight = screen.frame.height - screen.visibleFrame.height - screen.visibleFrame.origin.y - 1
}
This number will not be correct only if there is some extra screen furniture (like the Dock for example) pinned from the top, which seems extremely unlikely.
Update: To support multiple displays (primary and secondary):
let appleMenuBarHeight = screen.frame.height - screen.visibleFrame.height - (screen.visibleFrame.origin.y - screen.frame.origin.y) - 1
The non-programmatic-6-nanoseconds way I would find out:
The info panel will tell you the height (and width).
(sןǝxıd oʍʇ-ʎʇuǝʍʇ :ɹǝʍsuɐ)
(ɹns ƃᴉq soɔɐɯ ǝɔuᴉs slǝxᴉd ǝʌᴉɟ-ʎʇuǝʍʇ :ǝʇɐpdn)