NSTextField - White text on black background, but black cursor

后端 未结 9 1068
温柔的废话
温柔的废话 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 16:54

    If you use Objective-C runtime selector capture combined with uliwitness's solution, you can achieve it without subclassing NSTextField, here I use RxCocoa's methodInvoked as an example:

    import Cocoa
    import RxCocoa
    
    extension NSTextField {
        func withCursorColor(_ color: NSColor) {
            rx.methodInvoked(#selector(becomeFirstResponder))
                .subscribe(onNext: { [unowned self] _ in
                    guard let editor = self.currentEditor() as? NSTextView else { return }
                    editor.insertionPointColor = color
                })
                .disposed(by: rx.disposeBag)
        }
    }
    
    

提交回复
热议问题