swift - 使用 Swift 在 NSTextField 中拼写

标签 swift macos nstextfield spelling

如何使用 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?


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

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

关于swift - 使用 Swift 在 NSTextField 中拼写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35685390/

相关文章:

swift - Carthage 构建失败。(对于两个 Xcode)

ios - 如何更改 UIAlertController 的 UIAlertAction 处理程序中的全局值(添加函数)?

swift - snapkit 登录工具包无法正常工作 Swift Xcode 11.3.1

macos - NSImage 和视网膜显示混淆

python - 无法通过 RFCOMM 连接到设备,因为 'Resource Busy'

objective-c - 如何在 Cocoa 中自定义 NSTextField 外观(使用的字体、字体大小)?

objective-c - 在结束编辑时执行操作

ios - 无法使用 swift 4.1 创建自定义框架

python - 在新的终端窗口中打印

objective-c - 带有数字格式化程序的 NSTextField 不允许小数输入