4

如何NSTextField使用 swift 检查 a 的拼写?我已经controlTextDidChange用来验证文本。该解决方案似乎提到将第一响应者转换为 aNSTextView但我不确定是否可以通过 swift 强制使用。我知道如果我改为 a 会更容易,NSTextView但如果可能的话,我想避免这种情况。

4

1 回答 1

2

这应该可以帮助你。

// Focus TextField
phraseTextField.becomeFirstResponder()
// Enable Continous Spelling
let textView: NSTextView = (self.window!.firstResponder as! NSTextView)
textView.continuousSpellCheckingEnabled = true

改编自:如何在 Mac OS X 上的 NSTextField 中启用拼写检查?


在其他情况下,将 s 更改NSTextFieldNSTextViews 可能会更好。只需使用“文本视图”(在对象库中搜索 NSTextView),拼写检查将默认打开。据我所知,NSTextFields 在某些情况下根本不支持拼写检查。

另请参阅:https ://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTextView_Class/#//apple_ref/doc/uid/20000373-SW55

于 2016-02-28T19:13:43.640 回答