Dan Pristupov
Dan Pristupov

Reputation: 51

Custom NSTextFieldCell draws text differently

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

Upvotes: 2

Views: 670

Answers (1)

Mark
Mark

Reputation: 6947

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.

Upvotes: 2

Related Questions