Search code examples
swiftmacosreact-nativenswindownspanel

Make NSPanel always on top


I'm making a bridge for react-native-macos. I need NSPanel with the same behaviour as Spotlight. I programmatically created it, but have questions:

  1. Can't make it always on top (also it should work if app is hidden)
  2. There is NSTextField inside the panel. If I try to hide title panel I can't change the field. Looks like it disabled.
  3. What is the best way to display results (like in the spotlight)
private var panel = NSPanel()
private var textField = NSTextField(frame: NSMakeRect(0,0,400,40))

var frame: NSRect = CGRect(x: 0, y: 0, width: 400, height: 40)
frame.size = NSSize(width: 400, height: 60)
panel.setFrame(frame, display: true)
  
let view: NSView = NSView(frame: frame)
    
myTextField.stringValue = "Some text"
myTextField.isEnabled = true
myTextField.font = NSFont.systemFont(ofSize: 28)
    
view.addSubview(myTextField)

panel.contentView?.addSubview(view)

panel.makeKeyAndOrderFront(panel)
panel.center()

Solution

  • This works for me

    panel.level = .mainMenu