如果删除边框,TableView选择看起来很奇怪

问题描述 投票:0回答:1

我有一个非常标准的NSTableView(这是Mac,而不是iOS),其中包含一些文本行。每行是一个NSTextField。我对文本字段的边框不满意(参见图片),因此将其删除。但是这样做,所选单元格看起来很奇怪。

我该如何解决?

之前:enter image description here

之后enter image description here

注意:

- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row  {
    NSTextField *cell = [tableView makeViewWithIdentifier:@"MyView" owner:self];
    if (cell == nil) {
        cell = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, tableView.bounds.size.width, 30)];
        cell.identifier = @"MyView";
        cell.editable = NO;
        cell.bordered = NO;
    }
    cell.stringValue = [NSString stringWithFormat:@"row %d", row];
    return cell;
}

我尝试设置cell.selectable = YES,但没有帮助。我也尝试过在情节提要中使用某些属性(“对焦环”,...),但是它也不起作用。有什么主意吗?

cocoa nstableview
1个回答
0
投票

设置cell.backgroundColor = [NSColor clearColor];完成了trick俩(透明背景)

© www.soinside.com 2019 - 2024. All rights reserved.