fahad khan
fahad khan

Reputation: 89

How to change insertion text (cursor) for NStextField? for os x swift 2

the most relevant code i found was let fieldEditor = self.window?.fieldEditor(true, forObject: textField) as! NSTextView? fieldEditor!.insertionPointColor = NSColor.redColor() but doesn't work because field editor is nil i tried this using in subclass of textfield.

Upvotes: 0

Views: 889

Answers (1)

fahad khan
fahad khan

Reputation: 89

Never mind found the answer by extending NSTextField class and calling the function manually

extension NSTextField {
   public func customizeCaretColor(caretColor: NSColor) {
      let fieldEditor = self.window?.fieldEditor(true, forObject: self) as! NSTextView
      fieldEditor.insertionPointColor = caretColor
   }
}

Upvotes: 2

Related Questions