2

テーブルビューの列ヘッダーを垂直方向に表示するエレガントな方法を見つけるのに苦労しています(従来の方法から反時計回りに90度回転)。私は実際のNSTableHeaderCellとしてこれを行うことと結婚していません。NSTextFieldCellまたはNSCellをオーバーライドする方が簡単かもしれないと考えました。

セルには編集不可能なテキストのみが含まれていますが、通常は2行であり、コンテキストによっては列の残りの部分で色付けされる場合があります。

私はこれを行うカカオアプリを見つけることができないようです。ましてやオープンソースの例です。何かご意見は?

4

1 に答える 1

2
#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
于 2010-05-02T16:27:45.947 に答える