Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kristopherjohnson/5826441eebc7e8f15086 to your computer and use it in GitHub Desktop.
Save kristopherjohnson/5826441eebc7e8f15086 to your computer and use it in GitHub Desktop.
Snippet to programmatically set initial position of an Cocoa window
import Cocoa
class MyInitiallyPositionedWindowController: NSWindowController {
override func windowDidLoad() {
super.windowDidLoad()
if let window = window, screen = window.screen {
let screenRect = screen.visibleFrame
let offsetFromLeft = CGFloat(200)
let offsetFromTop = CGFloat(200)
let offsetFromBottom = screenRect.maxY - window.frame.height - offsetFromTop
window.setFrameOrigin(NSPoint(x: offsetFromLeft, y: offsetFromBottom))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment