Vertically center NSTextFieldCell?

5.3k views Asked by At

I have an NSTableView where I am changing the height of the rows with the following code:

- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row
{
    return 32;
}

The problem is, my text cells are still being aligned to the top of the cell, making it look awkward. I havent been able to figure out how to vertically center it. Has anyone else found a solution to this?

1

There are 1 answers

2
Quinn Taylor On BEST ANSWER

See "Is there a “right” way to have NSTextFieldCell draw vertically centered text?"

There is currently no easy way using only public API. The question linked above mentions that the undocumented _cFlags.vCentered field is the quickest path to making it work, although it's unsupported and isn't guaranteed to work correctly. Also, be aware that overriding methods will cause your code to diverge from what AppKit does.

I just filed a Radar for this:

http://openradar.appspot.com/9028329 Add public API for vertically centering text in NSCell


EDIT: Here are some additional related resources:

http://www.red-sweater.com/blog/148/what-a-difference-a-cell-makes

http://www.cocoabuilder.com/archive/cocoa/174994-repositioning-an-nstextfieldcell.html