Popover
- Select your xib interface, Drag a button into the view, and change button title to "Show Popover".
- Declare popover variable in the controller class.
- Define a function called showPopoverAction, Connect button action to it, in where you can write show popover code.
The reference code is implemented as follows:
import Cocoa
class HDPopoverVC: NSViewController {
lazy var popover: HDPopover? = {
let popover = HDPopover()
return popover
}()
override func viewDidLoad() {
super.viewDidLoad()
// Do view setup here.
}
@IBAction func showPopoverAction(_ sender: Any) {
if let button = sender as? NSButton {
if let view = button.superview {
let pointInWindow = view.convert(button.frame, to: nil)
popover?.show(relativeTo: pointInWindow, of: view, preferredEdge: .minY)
}
}
}
}