にパディングを追加するにはどうすればよいNSTableCellView
ですか?
プレーンな HTML で行う場合と同様に、コンテンツに 10px のパディングが必要です。(すべての側面)。テキストは垂直方向の中央に配置する必要があります。
現時点では、NSTextFieldCell のサブクラスでこれを行っています。しかし、これは正しく機能していないようです。
テキストを編集すると、編集テキスト フィールドは textfieldcell のパディングを使用しません。
画像 2:
これが私が現在持っているコードです(のサブクラスNSTextFieldCell
)
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
NSRect titleRect = [self titleRectForBounds:cellFrame];
NSAttributedString *aTitle = [self attributedStringValue];
if ([aTitle length] > 0) {
[aTitle drawInRect:titleRect];
}
}
- (NSRect)titleRectForBounds:(NSRect)bounds
{
NSRect titleRect = bounds;
titleRect.origin.x += 10;
titleRect.origin.y = 2;
NSAttributedString *title = [self attributedStringValue];
if (title) {
titleRect.size = [title size];
} else {
titleRect.size = NSZeroSize;
}
// We don't want the width of the string going outside the cell's bounds
CGFloat maxX = NSMaxX(bounds);
CGFloat maxWidth = maxX - NSMinX(titleRect);
if (maxWidth < 0) {
maxWidth = 0;
}
titleRect.size.width = MIN(NSWidth(titleRect), maxWidth);
return titleRect;
}