使用 Swift 在 NSTextField 中拼写

Spelling in NSTextField with Swift

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

这应该能帮到你。

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

改编自:How do I enable spell checking within an NSTextField on Mac OS X?


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

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