NSTableView自定义头视图NSTableHeaderVi
2020-03-19 本文已影响0人
路漫漫其修远兮Wzt
#import "MTDownloadTableHeaderCell.h"
@implementation MTDownloadTableHeaderCell
-(instancetype)initTextCell:(NSString *)string {
if (self = [super initTextCell:string]) {
}
return self;
}
-(void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
[super drawWithFrame:cellFrame inView:controlView];
[iColor(0xff, 0xff, 0xff, 1.0) setFill];
NSRectFill(cellFrame);
[self drawInteriorWithFrame:cellFrame inView:controlView];
}
-(void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
CGRect titleRect = [self titleRectForBounds:cellFrame];
titleRect.origin.x += 15;
titleRect.origin.y += 5;
titleRect.size.width -= 15;
[self.attributedStringValue drawInRect:titleRect];
}
@end
//设置自定义头视图
-(void)setCustomTableHeaderView {
[self.tableView setBackgroundColor:[NSColor clearColor]];
[[self.tableView tableColumns] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSString *columnTitle = [[obj headerCell] stringValue];
MTDownloadTableHeaderCell *myCell = [[MTDownloadTableHeaderCell alloc] initTextCell:columnTitle];
[obj setHeaderCell:myCell];
}];
}