Vertically center NSTextFieldCell?
Asked Answered
R

1

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?

Rammer answered 19/2, 2011 at 17:18 Comment(3)
You know you can configure the row height in Interface Builder, right?Doggoned
possible duplicate of Is there a "right" way to have NSTextFieldCell draw vertically centered text?Doggoned
Row height isn't the issue, it's vertical alignment for taller row heights.Exorcise
E
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

Exorcise answered 20/2, 2011 at 5:17 Comment(2)
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?Montreal
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)Fredericafrederich

© 2022 - 2024 — McMap. All rights reserved.