1

NSTableView (ビュー ベース モード) のフォント サイズを大きくして、アプリの何らかのプレゼンテーションで読みやすくする必要があります。

フォントの変更は、次の範囲内で正常に機能します- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row

    NSTableCellView *cellView = [tableView makeViewWithIdentifier:identifier owner:self];
    [cellView.textField setFont:self.tableFont];
    cellView.textField.stringValue = rowData[row];
    [cellView.textField setNeedsDisplay:YES];

また、rowHeight を- (CGFloat) tableView:(NSTableView *)tableView heightOfRow:(NSInteger)rowで更新します。これも機能します。

- (CGFloat) tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row {
    if (self.tableFont) {
        NSLog(@"Setting row height to %.1f", [self.tableFont pointSize]+8);
        return [self.tableFont pointSize] + 8;
    }
    return [NSFont systemFontSize] + 8;
}

(正しい高さを決定するもっとエレガントな方法があるかもしれません)

さて、ここに私の問題があります。フォントが変更されているのがわかります。また、rowHeight が変更されていることもわかります (別の行の色を使用しているため、見やすくなっています)。しかし、セル内のテキストは元の高さ (おそらく 17 ピクセル) に切り詰められているように見えるため、フォント サイズを大きくすると、書き込みの上部のみが表示され、次に空白が表示され、次の行の上部が再び表示されます。 .

私にとっては、一部のビューが NSTableViewCell を古い高さにクリップしているように見えます...私はすでにフレームと境界を異なる値に設定して遊んでいましたが、これは何も変更しませんでした:

    NSRect rect = [cellView.textField frame];
    rect.origin.y = 1;
    rect.size.height = [self.tableFont pointSize] + 6;
    [[cellView.textField cell] setFrame:rect];
    [cellView.textField setFrame:rect];
    [cellView.textField setBounds:rect];
    [cellView.textField setNeedsDisplay:YES];
    [cellView setFrame:rect];
    [cellView setBounds:rect];
    [cellView setNeedsDisplay:YES];

私はここでちょっと迷っています...単純なものが欠けていると思いますが、どこを見ればいいのかわかりません...

ありがとう、ジャン

4

1 に答える 1

2

autolayout パスがヒットしたときに NSTextField が自動的に大きくなるように、制約が設定されていることを確認する必要があります。NSTextField の高さには、fontSize に基づく固有の高さがあるため、制約があってはなりません。

また、ビューベース モードでは、cellView の 'textField' および 'imageView' アウトレットが特別に扱われるという誤機能もあります。レイアウトに関する独自のルールを破っています。(これは、レーダー 11713245 & 15359487 としてファイルされています)。

10.8 および 10.9 のカスタム NSTableCellView クラスでこの誤機能を回避するために使用するコードを次に示します。私の場合、フィールドの x オフセットのみをリセットする必要があることに注意してください。

#pragma mark NSView

- (void)viewWillDraw;
{
    const NSRect imageViewFrame = self.imageView.frame, textFieldFrame = self.textField.frame;

    [super viewWillDraw]; // NSTableCellView in  source list-mode outline view will apply custom metrics and positioning here by calling -_doStandardRowSizeStyleLayout, which manually calls setFrame: on the textField and imageView, screwing up our autolayout...

    // ...so put the x offsets back the way we really wanted them, dammit (Radar 11713245, 15359487)
    if (imageViewFrame.origin.x != self.imageView.frame.origin.x)
        [self.imageView setFrameOrigin:(NSPoint){imageViewFrame.origin.x, self.imageView.frame.origin.y}];

    if (textFieldFrame.origin.x != self.textField.frame.origin.x)
        [self.textField setFrameOrigin:(NSPoint){textFieldFrame.origin.x, self.textField.frame.origin.y}];
    if (textFieldFrame.size.width != self.textField.frame.size.width)
        [self.textField setFrameSize:(NSSize){textFieldFrame.size.width, self.textField.frame.size.height}];
}
于 2014-01-11T07:21:22.790 に答える