NSTextFieldCell或只有NSCell与垂直文本(和彩色着色)
我努力寻找一种以垂直方式显示表视图的列标题的优雅方式(从传统逆时针旋转90度)。 我并没有把这个做成一个真正的NSTableHeaderCell,我想通过重写NSTextFieldCell或NSCell可能会更容易。
单元格只包含不可编辑的文本,但通常是两行,并且根据上下文有时会与列的其余部分一起着色。
我似乎无法找到任何这样做的可可应用程序,更不用说开源示例。 有什么想法吗?
#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/85205.html
上一篇: NSTextFieldCell or just NSCell with vertical text (and colored tinting)
下一篇: How to remove black edge on UIImageView with rounded corners and a border width?