如何在NSTableView中设置列边距? [英] How do I set the column margins in an NSTableView?

查看:206
本文介绍了如何在NSTableView中设置列边距?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的NSTableView的列边距添加更多的填充(即在列的左侧和列文本之间更多的间隙)。

I would like to add more padding to the column margins in my NSTableView (ie. more gap between the left side of the column and the column text).

调用setIntercellSpacing为行的技巧,但它使列标题边距不受影响。任何人都可以提供解决方案?

Calling setIntercellSpacing does the trick for the rows, but it leaves the column heading margin unaffected. Can anyone offer a solution?

感谢

推荐答案

首先说,在表列标题单元格文本之间有边距有点奇怪,但这只是我的意见。

I'll first say it's a little weird to have margins between table column header cell text, but that's just my opinion.

没有API支持的方式来做这个确切的事情我所知。你可以通过请求列的标题单元格(它是NSTextFieldCell的子类),设置其属性字符串值(通过-setAttributedStringValue:)来实现效果。您可能还需要将-setAllowsEditingTextAttributes设置为YES,但是我不确定。

There's no API-supported way to do this exact thing as far as I know. You can probably achieve the effect by asking the column for its header cell (which is a subclass of NSTextFieldCell), setting its attributed string value ( via -setAttributedStringValue: ). You might have to also set -setAllowsEditingTextAttributes: to YES but I'm not sure.

另一种方法是子类化NSTableHeaderCell并覆盖-titleRectForBounds:复制矩形超级返回。然后,您必须通过-setHeaderCell:

The alternative is to subclass NSTableHeaderCell and override -titleRectForBounds: to pass a width-inset copy of the rectangle super returns. You'd then have to replace the columns' header cells via -setHeaderCell:.

这篇关于如何在NSTableView中设置列边距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆