swift - NSTextView backgroundColor 属性
问题描述
我无法在我的 NSTextView 上使用背景颜色。我使用以下属性:
myTextView.typingAttributes = [
NSAttributedString.Key.font: NSFont(name: "Helvetica", size: 16.0)!,
NSAttributedString.Key.foregroundColor: NSColor.textColor,
NSAttributedString.Key.kern: 2,
] as [NSAttributedString.Key: Any]
myTextView.selectedTextAttributes = [NSAttributedString.Key.foregroundColor: NSColor.systemRed,
NSAttributedString.Key.backgroundColor: NSColor.systemYellow]
如上所示,文本正确显示,当我选择文本时,字体按预期变为红色。但是文本的背景颜色不会变为黄色。它发生在暗模式和亮模式(Mojave)中。
我在这里想念什么?
编辑
我找到了造成这种情况的原因。我正在使用NSLayoutManager
我覆盖的自定义drawBackground(forGlyphRange glyphsToShow: NSRange, at _: NSPoint)
。但是,我没有调用它的 super,因此取消了 backgroundColor 属性。
解决方案
推荐阅读
- meshlab - 如何在 MeshLab 中显示 Hausdorff 距离的热图?
- c# - 在 C# 中仅继承派生类中的有限属性
- java - 不能在其他类 Android (Java) 中使用构造函数
- python-3.x - 虽然循环不循环 - Python
- php - Laravel 6.0 不支持 DELETE、PUT 方法
- sql - SUM 结果乘以行数
- gatsby - 使用 NGINX 问题服务 gatsby 生产
- node.js - 用于页面的 Nodejs Facebook 聊天机器人
- flutter - 如何在 ExpansionTile Flutter 中使用动态 TextField 控制器
- hibernate - 更改架构文件名后的 Corda SQLGrammarException