NSPopover color

前端 未结 3 1792
终归单人心
终归单人心 2021-02-15 10:48

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.

3条回答
  •  悲&欢浪女
    2021-02-15 11:28

    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.

提交回复
热议问题