How to change NSPopover background color include triangle part?

后端 未结 8 622
无人及你
无人及你 2020-12-02 23:25

How can I change NSPopover background color include triangle part?

\"enter

8条回答
  •  再見小時候
    2020-12-03 00:11

    Thanks to Stefanf I got this working. Here is a Swift version of the View code. As noted, this should be the class for the View set as your NSPopOver contentView.

    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 = NSAutoresizingMaskOptions([.ViewWidthSizable, .ViewHeightSizable]);
                    frameView.addSubview(backgroundView!, positioned: NSWindowOrderingMode.Below, relativeTo: frameView)
                }
            }
        }
    }
    
    
    
    class PopoverBackgroundView:NSView {
        override func drawRect(dirtyRect: NSRect) {
            NSColor.redColor().set()
            NSRectFill(self.bounds)
        }
    }
    

提交回复
热议问题