2

I have view-based NSTableView with 2 text columns.

First column uses custom NSTextFieldCell. Second column uses the default cell.

Here's the custom cell code:

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)
    }
}

Somehow the text fields in the custom (first) column look differently (thinner?). Here's the screenshot (Sierra).

Not sure what's going on, may be custom implementation uses different antialiasing settings.

What am I missing there? Thank you in advance.

edit: mentioned view-based NSTableView

Dan Pristupov
  • 51
  • 1
  • 8
  • Similar question: [drawTitle:withFrame:inView Changes font looks when it shouldn't](http://stackoverflow.com/questions/41640285/drawtitlewithframeinview-changes-font-looks-when-it-shouldnt). – Willeke Jan 22 '17 at 17:49
  • @Willeke Thanks. Looks like there's still no solution :( – Dan Pristupov Jan 22 '17 at 18:08
  • I created test project based on your description and it renders fine: https://github.com/emankovski/TableRendersFine So maybe something else you forgot to mention? – Eugene Mankovski Jan 24 '17 at 00:41
  • @EugeneMankovski Sorry, I didn't mention that I use View-Based NSTableView. However I added a much simpler case with just 2 textfields to your project: https://github.com/DanPristupov/TableRendersFine. There's a slight difference between the textfields: https://dl.dropboxusercontent.com/s/vty1w647j840kkq/2017-01-24%20at%2008.08.png – Dan Pristupov Jan 24 '17 at 07:23
  • Text field still relies on its cell in rendering a lot. Maybe create custom NSTextFieldCell if you need any custom drawing? – Eugene Mankovski Jan 24 '17 at 16:26
  • @EugeneMankovski I just updated the example (https://github.com/DanPristupov/TableRendersFine) to show that custom NSTextFieldCell also draws itself incorrectly. Am I missing something? – Dan Pristupov Jan 24 '17 at 17:13
  • Yea I tried different things and nothing helps. Feels like a Cocoa bug. I suspect someone from Apple dev team could explain what is going on. My guess is that something has to be set for proper superclass rendering... – Eugene Mankovski Jan 24 '17 at 23:22

1 Answers1

2

Looks like that bug still exists today. Overriding NSTextField.draw(_ dirtyRect: NSRect) or NSTextFieldCell.draw(withFrame cellFrame: NSRect, in controlView: NSView) and simply calling super is enough to reproduce this behavior.

As a workaround, set textField.drawsBackground = false, place your text field into an NSBox or custom NSView and handle your drawing there.

Mark
  • 6,647
  • 1
  • 45
  • 88