質問

私は行を作成するNStableView(ビューベース)を持っています。

- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
    TaskTableCellView *tableCellView = [[TaskTableCellView alloc] init];
    return tableCellView;
}

-(void) tableView:(NSTableView *)tableView didAddRowView:(NSTableRowView *)rowView forRow:(NSInteger)row {
    NSView *view = [rowView viewAtColumn:0];
    [view setTranslatesAutoresizingMaskIntoConstraints:NO];
    NSDictionary *views = NSDictionaryOfVariableBindings(view);
    [tableView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[view]|" options:0 metrics:nil views:views]];
    [tableView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view]|" options:0 metrics:nil views:views]];
}

- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row {
    return 20;
}
.

この行はいくつかのサブビューを作成し、いくつかの制約を割り当てます。

- (void)layout {
    [super layout];
    ViewWithBackground *viewWithBackground = [[ViewWithBackground alloc] init];
    viewWithBackground.backgroundColor = [NSColor greenColor];
    [self addSubview:viewWithBackground];

    [viewWithBackground setTranslatesAutoresizingMaskIntoConstraints:NO];
    NSDictionary *views = NSDictionaryOfVariableBindings(viewWithBackground);
    [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[viewWithBackground]|"
                                                                 options:0
                                                                 metrics:nil
                                                                   views:views]];
    [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[viewWithBackground]|"
                                                                 options:0
                                                                 metrics:nil
                                                                   views:views]];

    [viewWithBackground setContentHuggingPriority:200 forOrientation:NSLayoutConstraintOrientationVertical];
    [viewWithBackground setContentHuggingPriority:200 forOrientation:NSLayoutConstraintOrientationHorizontal];
}


- (void)drawRect:(NSRect)dirtyRect {
    [[NSColor redColor] set];
    NSRectFill(dirtyRect);
    [super drawRect:dirtyRect];
}
.

私が実際に制約を編集しようとしたときに楽しいスタートを始める。制約が| [ViewWithBackground] |水平と垂直の両方の場合、予想される結果 - 緑色の行が得られます。私がそれを最も基本的なものに変えるとき - [ViewWithBackground] - |、私は明らかに予想外の結果 - 赤い行を取得し、私の緑色のビューの兆候はありません!

ここに連れて行くことになっているいくつかの追加ステップはありますか?私の目標は、私のViewWithBackgroundが実際には少し小さいビューになることです。行とテーブルビューのエッジからの間隔からの間隔を偽造します..

役に立ちましたか?

解決

誰かがこれを震えている場合.. NstableCellViewが最小サイズなしでは少しの手のもの字であることがわかります。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top