Skip to content

Instantly share code, notes, and snippets.

@steve228uk
Last active October 10, 2021 07:23
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steve228uk/c960b4880480c6ed186d to your computer and use it in GitHub Desktop.
Save steve228uk/c960b4880480c6ed186d to your computer and use it in GitHub Desktop.
Move NSWindow standardWindowButtons in Swift
// Add this to your main view.
override func viewDidLayout() {
super.viewDidLayout()
if let btn = view.window?.standardWindowButton(.closeButton) {
btn.removeFromSuperview()
btn.setFrameOrigin(NSPoint(x: 12, y: 28))
view.addSubview(btn)
}
if let btn = view.window?.standardWindowButton(.miniaturizeButton) {
btn.removeFromSuperview()
btn.setFrameOrigin(NSPoint(x: 32, y: 28))
view.addSubview(btn)
}
if let btn = view.window?.standardWindowButton(.zoomButton) {
btn.removeFromSuperview()
btn.setFrameOrigin(NSPoint(x: 52, y: 28))
view.addSubview(btn)
}
}
@WuZiHong
Copy link

hi,I use your code with playground,then i put a button to the playground ,when i run the program ,Xcode warn:

2016-08-21 13:37:59.105 airprojectS[5072:144369] Layout still needs update after calling -[NSView layout]. NSView or one of its superclasses may have overridden -layout without calling super. Or, something may have dirtied layout in the middle of updating it. Both are programming errors in Cocoa Autolayout. The former is pretty likely to arise if some pre-Cocoa Autolayout class had a method called layout, but it should be fixed.

can you help me to solve the program? thank u

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment