NSTextField in NSTableCellView

前端 未结 4 2001
面向向阳花
面向向阳花 2021-01-01 03:20

I have a view based NSTableView with a custom NSTableCellView. This custom NSTableCellView has several labels (NSTextField). The whole UI of the NSTableCellView is built in

4条回答
  •  北荒
    北荒 (楼主)
    2021-01-01 04:06

    This works no matter what style the table view has:

    - (void)setBackgroundStyle:(NSBackgroundStyle)backgroundStyle {
        [super setBackgroundStyle:backgroundStyle];
        NSTableView *tableView = self.enclosingScrollView.documentView;
        BOOL tableViewIsFirstResponder = [tableView isEqual:[self.window firstResponder]];
        NSColor *color = nil;
        if(backgroundStyle == NSBackgroundStyleLight) {
            color = tableViewIsFirstResponder ? [NSColor lightGrayColor] : [NSColor darkGrayColor];
        } else {
            color = [NSColor whiteColor];
        }
        myTextField.textColor = color;
    }
    

提交回复
热议问题