8

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?

Quinn Taylor
  • 44,553
  • 16
  • 113
  • 131
Kyle
  • 17,317
  • 32
  • 140
  • 246
  • You know you can configure the row height in Interface Builder, right? – Nicholas Riley Feb 20 '11 at 05:07
  • possible duplicate of [Is there a "right" way to have NSTextFieldCell draw vertically centered text?](http://stackoverflow.com/questions/1235219/is-there-a-right-way-to-have-nstextfieldcell-draw-vertically-centered-text) – Nicholas Riley Feb 20 '11 at 05:08
  • 3
    Row height isn't the issue, it's vertical alignment for taller row heights. – Quinn Taylor Feb 20 '11 at 05:19

1 Answers1

6

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

Community
  • 1
  • 1
Quinn Taylor
  • 44,553
  • 16
  • 113
  • 131
  • 3
    slightly off-topic but what is the advantage of filling an open radar instead or a regular bugreport.apple.com? Will Apple read open radars? – Duck Jan 05 '15 at 19:59
  • SpaceDog: Preferably you should use both, but if you don't have the time, use Apple's, it's more important. bugreport.apple.com is what Apple sees, then you can create an openradar version of the same bugreport so that the community will see that others have already encountered the same problem, and reported to Apple. (Apple's bugreported is private) – Zsolt Szatmari Mar 10 '15 at 10:18