如何使圆角NSTableView行? [英] How to make round cornered NSTableView rows?
本文介绍了如何使圆角NSTableView行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想做这样的事情(在新的iTunes上):
I'd like to make something like this (on the new iTunes):
正如你所当行被选中的亮点"的状态看到的是一个圆角的行.结果 我该如何实现这样的目标?
As you can see when the row is selected it's "highlight" state is a round cornered row.
How can I achieve something like this?
推荐答案
您需要将NSTableview
子类化并覆盖-highlightSelectionInClipRect:
方法.
You need to subclass NSTableview
and override -highlightSelectionInClipRect:
method.
可以这样做:
在 Attributes Inspector 中将tableView的突出显示模式从常规更改为源列表:
Change your tableView's highlighting mode from regular to Source list in Attributes Inspector:
现在像这样子类NSTableView
:
-(void)highlightSelectionInClipRect:(NSRect)theClipRect
{
NSRange visibleRowIndexes = [self rowsInRect:theClipRect];
NSIndexSet *selectedRowIndexes = [self selectedRowIndexes];
NSUInteger endRow = visibleRowIndexes.location + visibleRowIndexes.length;
NSUInteger row;
for (row=visibleRowIndexes.location; row<endRow; row++)
{
if([selectedRowIndexes containsIndex:row])
{
NSRect rowRect = NSInsetRect([self rectOfRow:row], 3, 4);
NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:rowRect xRadius:4.0 yRadius:4.0];
[[NSColor colorWithCalibratedRed:0.474 green:0.588 blue:0.743 alpha:1] set];
[path fill];
}
}
}
结果:
这篇关于如何使圆角NSTableView行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文