Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertically center NSTextFieldCell?

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?

like image 693
Kyle Avatar asked Feb 19 '11 17:02

Kyle


1 Answers

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

like image 160
Quinn Taylor Avatar answered Nov 07 '22 12:11

Quinn Taylor