问题
This may be very trivial question but I am not able to figure it out. I have removed titlebar of a window by-
self.window?.styleMask = NSBorderlessWindowMask
self.window?.movableByWindowBackground = true
Now Any textfield is not working and are disabled because without title bar canBecomeKeyWindow is set to false. Please refer This
How I can set it to true?
I have tried
self.window?.makeKeyWindow()
But it is not working. Thanks for your help.
回答1:
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
}
}
来源:https://stackoverflow.com/questions/30776875/how-to-set-canbecomekeywindow