首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSTableCellView填充

NSTableCellView填充
EN

Stack Overflow用户
提问于 2014-11-25 19:15:29
回答 1查看 1.2K关注 0票数 6

如何将填充添加到NSTableCellView中?

我希望内容填充为10 it,类似于在普通HTML中这样做。(各方面)。课文应在中间垂直居中。

目前,我正在NSTextFieldCell的子类中执行此操作。但这似乎不正确。

编辑文本时,编辑文本字段不使用来自textfieldcell单元格的填充。

图2:

下面是我目前拥有的代码(NSTextFieldCell的子类)

代码语言:javascript
复制
- (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; 
}
EN

回答 1

Stack Overflow用户

发布于 2014-11-28 16:12:47

使用setContentInset method.it设置内嵌在内容视图和封闭表视图之间的距离。

例如

代码语言:javascript
复制
self.tableView.contentInset = UIEdgeInsetsMake(-35, 0, -20, 0);
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27134831

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档