NSTextFieldCell 或仅带有垂直文本(和彩色着色)的 NSCell

发布于 2024-08-30 21:36:40 字数 234 浏览 3 评论 0原文

我正在努力寻找一种优雅的方式以垂直方式显示表视图的列标题(与传统方式逆时针旋转 90 度)。我并不想将其作为实际的 NSTableHeaderCell 来执行此操作,我认为通过覆盖 NSTextFieldCell 或 NSCell 来完成此操作可能会更容易。

单元格仅包含不可编辑的文本,但通常是两行,有时根据上下文与列的其余部分一起着色。

我似乎找不到任何可以执行此操作的可可应用程序,更不用说开源示例了。有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少年亿悲伤 2024-09-06 21:36:40
#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
#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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文