Abhishek
Abhishek

Reputation: 882

How to set canBecomeKeyWindow?

I have removed the title bar of a window with:

self.window?.styleMask = NSBorderlessWindowMask
self.window?.movableByWindowBackground = true

Now the text fields are not working and are disabled because without title bar canBecomeKeyWindow is set to false, as specified in the official documentation.

I have tried:

self.window?.makeKeyWindow()

But it is not working. How I can set it to true?

Upvotes: 4

Views: 2200

Answers (1)

Paul Patterson
Paul Patterson

Reputation: 6918

If a variable is read-only (i.e. { get }, rather than { get set }) you can't set it (... = ...), you can only read it. To make sure it's returning the value you want when you do read it, you need to subclass the class in question, override the relevant property, and return that value:

class PPWindow: NSWindow {

    override var canBecomeKeyWindow: Bool {
        return true
    }
}

Upvotes: 12

Related Questions