Search code examples
xcodeswiftmacosnstableviewnsmenuitem

Setting maximum height for NSScrollView inside NSMenuItem


i am currently working on a menu bar application for OS X. I want do display some data in a NSTableView within the menu. I already managed to set the view of the first NSMenuItem to my NSScrollView. The problem is that i don't know how to set the maximum height for the NSScrollView. I want something similar to the Shazam or Adobe Creative Cloud app: A small menu with a TableView inside it that scrolls but doesn't fill the entire height of the screen.

Here is what i currently have:

NSScrollView inside NSMenuItem

The way it works now is that the menu automatically fills the entire screen depending on how much data i put into the TableView.

Here is a screenshot of the way the Shazam app does it:

Shazam App

They display lots of information inside the table but restricted the NScrollView to have a fixed height.

I don't think this is hard to do but i don't know where to look for the option.

Any help would be really appreciated :)

Regards,

Timo


Solution

  • I finally figured it out! I assigned the wrong view to the NSMenuItem.

    Now i have two outlets inside my AppDelegate:

    @IBOutlet weak var myMenuItem: NSMenuItem!
    @IBOutlet weak var myScrollView: NSScrollView!
    

    Inside applicationDidFinishLaunching() i assign the NSScrollView to the view property of the NSMenuItem:

    func applicationDidFinishLaunching(aNotification: NSNotification) {
        ...
        self.myMenuItem.view = myScrollView
        ...
    }
    

    The problem i used to have that i set the menu items view to the NSTableView directly, not to the NSScrollView. Everything works fine now.

    Thats what the result is looking now:

    Final Result

    Exactly what i wanted :)

    Regards,

    Timo