Skip to content

Instantly share code, notes, and snippets.

@steve228uk
Last active Oct 10, 2021
Embed
What would you like to do?
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

WuZiHong commented Aug 21, 2016

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