Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSPopover color

Is there any way to color NSPopover? Ive seen apps like facetab etc that have cool colors and resizeable popovers, how is this done?

Ay guides, hints?

Thanks.

like image 753
Rasmus Styrk Avatar asked Oct 06 '11 21:10

Rasmus Styrk


2 Answers

Set popover.contentViewController.view as a subclass of NSView with a custom background drawing (i.e. override drawRect: and fill a rect with your custom background color).

Then set the popover.appearance = NSPopoverAppearanceHUD to remove the default border around the view.

Note that there will still be a very thin border around the view, so if you want to remove it completely, you may want to use MAAttachedWindow or a similar solution.

like image 51
Yoav Avatar answered Nov 01 '22 15:11

Yoav


In Swift 4:

  1. Go to File->New File->Cocoa Class
  2. Name your class. eg. PopColor. Make sure it is a subclass of NSView
  3. Set the contents of the file to:
import Cocoa

class PopoverContentView:NSView {
    var backgroundView:PopoverBackgroundView?
    override func viewDidMoveToWindow() {
        super.viewDidMoveToWindow()
        if let frameView = self.window?.contentView?.superview {
            if backgroundView == nil {
                backgroundView = PopoverBackgroundView(frame: frameView.bounds)
                backgroundView!.autoresizingMask = NSView.AutoresizingMask([.width, .height]);
                frameView.addSubview(backgroundView!, positioned: NSWindow.OrderingMode.below, relativeTo: frameView)
            }
        }
    }
}

class PopoverBackgroundView:NSView {
    override func draw(_ dirtyRect: NSRect) {
        NSColor.green.set()
        self.bounds.fill()
    }
}
  1. In your storyboard, select the view which has your popover content and go to the Identity Inspector

  2. Set the Class to PopoverContentView

Your popover and its triangle will now be green.

like image 31
Ribena Avatar answered Nov 01 '22 17:11

Ribena