美文网首页
NSTableView自定义头视图NSTableHeaderVi

NSTableView自定义头视图NSTableHeaderVi

作者: 路漫漫其修远兮Wzt | 来源:发表于2020-03-19 15:21 被阅读0次

资料:https://stackoverflow.com/questions/19421314/custom-nstableheadercell-for-clear-background-of-nstableview

#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];
    }];
}

相关文章

网友评论

      本文标题:NSTableView自定义头视图NSTableHeaderVi

      本文链接:https://www.haomeiwen.com/subject/xarlyhtx.html