gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 16:39:35 25 4
gpt4 key购买 nike

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

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

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

最佳答案

#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

关于objective-c - NSTextFieldCell 或仅带有垂直文本(和彩色着色)的 NSCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2735056/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com