NSTextFieldCell or just NSCell with vertical text (and colored tinting)

I'm struggling with trying to find an elegant way of displaying the column headers for a table view in a vertical fashion (rotated 90 deg counter clockwise from traditional). I'm not married to doing this as an actual NSTableHeaderCell, I figured it might be easier to do it by overriding NSTextFieldCell or NSCell.

The cells only contain noneditable text, but it's usually two lines of it, and it's sometimes tinted with the rest of the column depending on the context.

I can't seem to find any cocoa apps that do this, much less an open source example. Any thoughts?


#import "VerticalTextCell.h"

@implementation VerticalTextCell

- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {

    NSMutableDictionary *atr = [NSMutableDictionary dictionary];
    NSFont *font = [NSFont fontWithName:@"Lucida Grande" size:12];
    [atr setObject:font forKey:NSFontAttributeName];

    [[[self backgroundColor] colorWithAlphaComponent:0.7] set];
    NSRectFillUsingOperation(cellFrame, NSCompositeSourceOver);

    NSGraphicsContext *currentContext = [NSGraphicsContext currentContext];
    [currentContext saveGraphicsState];

    NSAffineTransform *transform = [NSAffineTransform transform];
    [transform translateXBy:NSMinX(cellFrame) yBy:NSMinY(cellFrame)];
    [transform rotateByDegrees:-90];
    [transform concat];

    // vertical inset 5 pixels
    [[self stringValue] drawInRect:NSMakeRect(-NSHeight(cellFrame),5,NSHeight(cellFrame),NSWidth(cellFrame)) withAttributes:atr]; 

    [currentContext restoreGraphicsState];

}


@end
链接地址: http://www.djcxy.com/p/85206.html

上一篇: NSTableView和数据验证?

下一篇: NSTextFieldCell或只有NSCell与垂直文本(和彩色着色)