现在的位置: 首页 > 综合 > 正文

基于视图的NSTableView的更改选择的颜色 -

2014年09月05日 ⁄ 综合 ⁄ 共 1959字 ⁄ 字号 评论关闭

Standard highlighting color in OS X applications is blue.在OS X应用程序的标准突出显示颜色是蓝色的。

Is it possible to change it to another color, eg gray?是否有可能将其更改为另一种颜色,如灰色?

Note that I am using the new view-based NSTableView available starting from OS X 10.7.请注意,我使用新的基于视图的NSTableView从OS
X 10.7。

  • Since you're using the view based NSTableView, you can subclass NSTableRowView, feed it to the table delegate method -
    (NSTableRowView *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row;
     , then customize your selection in the row view class.
    由于您使用的浏览NSTableView的,你也可以继承NSTableRowView,将它输入到表中的委托方法- (NSTableRowView
    *)tableView:(NSTableView *)tableView rowViewForRow:(NSInteger)row;
     ,然后定制选项行中的视图类。

    Here's an example:下面是一个例子:

     - (void)drawSelectionInRect:(NSRect)dirtyRect { if (self.selectionHighlightStyle != NSTableViewSelectionHighlightStyleNone) { NSRect selectionRect = NSInsetRect(self.bounds, 2.5, 2.5); [[NSColor colorWithCalibratedWhite:.65 alpha:1.0] setStroke]; [[NSColor colorWithCalibratedWhite:.82 alpha:1.0] setFill]; NSBezierPath *selectionPath = [NSBezierPath bezierPathWithRoundedRect:selectionRect xRadius:6 yRadius:6]; [selectionPath fill]; [selectionPath stroke]; } } 
  • You have to subclass NSTableView , and rewrite the functions below in order to change the alternating
    colors.
    您必须NSTableView子类,并改写了以下功能以改变交替的颜色。

    • (void) drawRow: (NSInteger) row clipRect: (NSRect) clipRect

    • (void) drawBackgroundInClipRect: (NSRect) clipRect ** This one to change the main and alternate color
      **
       (void) drawBackgroundInClipRect: (NSRect) clipRect **这一个改变的主力和替补的颜色**

    Use a for loop and insert this conditional (i % 2 == 0) to detect odd and even rows.使用for循环,并插入此条件(i
    % 2 == 0)
    来检测奇数行和偶数行。

  • It seems to me there is an option available to change this coz the documentation says three selection style and the default style in regular is
    blue, look at the image below..
    在我看来,有一个选项可以改变这个堂妹的文件说,三个选择的风格和默认样式经常是蓝色的,看下面的图片......
     you need to send it a message which I cant
    figure out as I have never developed apps for mac before..
    你需要向它发送一个消息,我无法弄清楚,因为我从来没有开发适用于Mac的应用程序之前..
     hoping this helps...!希望这会有所帮助...!

    在这里输入的形象描述

抱歉!评论已关闭.