Edit AllPages


NSTextFieldCell adds to NSCell�s text display capabilities by allowing you to set the color of both the text and its background. You can also specify whether the cell draws its background at all. All of the methods declared by this class are also declared by NSTextField, which uses NSTextFieldCells to draw and edit text.


After some investigation, I’ve settled upon how to override text drawing within an NSTextFieldCell so that it appears indistinguishable from the same text drawn while the cell is being edited (through the field editor). The sample code below draws the cell’s attributed string contents including hyperlinks (normally, NSTextFieldCell does not draw styled hyperlinks):

Important in the above code is the configuration of the layout manager. Typesetter behavior is set to 10.2 with compatibility and usesFontLeading is set to NO. The textContainer’s line fragment padding is set to 2 - these settings cause lines of text to be rendered exactly as they are using the field editor. The expanded text frame should be established through experimentation. It will vary with the style of border you have set on your text field - in the case of a borderless text field, the inset is 0.