NSTextField - White text on black background, but black cursor

后端 未结 9 1067
温柔的废话
温柔的废话 2020-12-14 16:23

I\'ve setup an NSTextField with text color as white, and the background color as (black despite not rendering the background color, so its transparent). All in

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-14 17:02

    I've called insertionPointColor in viewDidLoad and app crashes.

    I fixed this by calling insertionPointColor on viewDidAppear.

    For Swift developers:

    Set insertionPointColor method into extension:

    extension NSTextField {
        public func customizeCursorColor(_ cursorColor: NSColor) {
            let fieldEditor = self.window?.fieldEditor(true, for: self) as! NSTextView
            fieldEditor.insertionPointColor = cursorColor
        }
    }
    

    and call

     override func viewDidAppear() {
            super.viewDidAppear()
            textField.customizeCursorColor(NSColor.red)
        }
    

提交回复
热议问题