我有基于 View 的 NSTableView,有 2 个文本列。
第一列使用自定义 NSTextFieldCell。第二列使用默认单元格。
这是自定义单元格代码:
class CustomTextFieldCell: NSTextFieldCell {
// don't do anything, just call the super implementation
override func drawInterior(withFrame cellFrame: NSRect, in controlView: NSView) {
super.drawInterior(withFrame: cellFrame, in: controlView)
}
}
不知何故,自定义(第一)列中的文本字段看起来有所不同(更薄?)。 这是screenshot (塞拉利昂)。
不确定发生了什么,可能是自定义实现使用了不同的抗锯齿设置。
我错过了什么?预先感谢您。
编辑:提到基于 View 的 NSTableView
最佳答案
看起来这个错误今天仍然存在。重写 NSTextField.draw(_ dirtyRect: NSRect) 或 NSTextFieldCell.draw(withFrame cellFrame: NSRect, in controlView: NSView) 并简单地调用 super足以重现此行为。
作为解决方法,设置 textField.drawsBackground = false
,将文本字段放入 NSBox
或自定义 NSView
并在那里处理您的绘图.
关于cocoa - 自定义 NSTextFieldCell 以不同方式绘制文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41793492/