2

In Cocoa on Mac OS X, I want to create an NSTableView where one column contains Ethernet hardware MAC addresses, and I want the characters of the MAC address in each row to all line up with the characters in the MAC addresses in rows above and below. I want to use a proportional font for all the other columns of the table, and switching to a separate non-proportional font for this one column is too jarring; it looks bad. I'd like to use the same typeface in the MAC address column as I use in the rest of the table.

So I really want to force Cocoa's text layout engine to lay out the text in this column in a non-proportional (a.k.a. fixed-width, monospace) manner, even though it's using a proportional typeface.

Any ideas on how to do that?

If these were just decimal digits I wouldn't have a problem, but MAC addresses are hexadecimal so they contain letters a-f, which throws off the spacing and vertical alignment.

Spiff
  • 608
  • 4
  • 11
  • 3
    There's no supported way to turn a proportional font into monospace. It just doesn't make sense. Technically, you could fake it by drawing each character individually and advancing the caret by a fixed width (ignoring the width of the actual character), but not only would this require drawing the text yourself, but it would also look extremely ugly. Please, just stick to using actual monospace fonts when you want something to be rendered monospace. Not only will that look better, but it's what people expect from monospaced text. – Lily Ballard Nov 28 '11 at 21:22
  • Depending on the font decimal digits can have differing widths, too. There are different digits for use in tables than for (body) text. – Nikolai Ruhe Nov 28 '11 at 22:16
  • 1
    Kevin, you should make your comment an answer. – Rob Keniger Nov 28 '11 at 23:12

0 Answers0