I want to be able to add a button to the title bar of all windows that open on a Mac.
The button will go on the right hand side, opposite the X -
Swift 4 - In NSWindowController
add the below code
if let window = window {
let myButton = NSButton()
myButton.title = "Help"
myButton.bezelStyle = .rounded
let titleBarView = window.standardWindowButton(.closeButton)!.superview!
titleBarView.addSubview(myButton)
myButton.translatesAutoresizingMaskIntoConstraints = false
titleBarView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:[myButton]-2-|", options: [], metrics: nil, views: ["myButton": myButton]))
titleBarView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-1-[myButton]-3-|", options: [], metrics: nil, views: ["myButton": myButton]))
}
Hope this is helpful.