如何将填充添加到NSTableCellView中?
我希望内容填充为10 it,类似于在普通HTML中这样做。(各方面)。课文应在中间垂直居中。
目前,我正在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;
}发布于 2014-11-28 16:12:47
使用setContentInset method.it设置内嵌在内容视图和封闭表视图之间的距离。
例如
self.tableView.contentInset = UIEdgeInsetsMake(-35, 0, -20, 0);https://stackoverflow.com/questions/27134831
复制相似问题