objective-c – 在Cocoa的NSTableView中更改突出显示的颜色?

objective-c – 在Cocoa的NSTableView中更改突出显示的颜色?,第1张

概述我正在开发一个Cocoa应用程序,并遇到突出显示的问题. MAC OS X应用程序中的标准突出显示颜色是蓝色的,但它不适合我的应用程序,因为设计概念,我需要一个绿色的突出显示. 我试图子类化NSTableview和override方法 - (void)highlightSelectionInClipRect:(NSRect)clipRect 但它没有帮助. 如果有人知道如何解决这个问题,请帮助我, 我正在开发一个Cocoa应用程序,并遇到突出显示的问题. MAC OS X应用程序中的标准突出显示颜色是蓝色的,但它不适合我的应用程序,因为设计概念,我需要一个绿色的突出显示.

我试图子类化NStablevIEw和overrIDe方法

- (voID)highlightSelectionInClipRect:(NSRect)clipRect

但它没有帮助.

如果有人知道如何解决这个问题,请帮助我,我会很感激.

阿尔乔姆

解决方法 我正在使用这个,到目前为止,这是完美的:

- (voID)highlightSelectionInClipRect:(NSRect)theClipRect{        // this method is asking us to draw the hightlights for         // all of the selected rows that are visible insIDe theClipRect        // 1. get the range of row indexes that are currently visible        // 2. get a List of selected rows        // 3. iterate over the visible rows and if their index is selected        // 4. draw our custom highlight in the rect of that row.    NSRange         aVisibleRowIndexes = [self rowsInRect:theClipRect];    NSIndexSet *    aSelectedRowIndexes = [self selectedRowIndexes];    int             aRow = aVisibleRowIndexes.location;    int             anEndRow = aRow + aVisibleRowIndexes.length;    NSGradIEnt *    gradIEnt;    NScolor *       pathcolor;        // if the vIEw is focused,use highlight color,otherwise use the out-of-focus highlight color    if (self == [[self window] firstResponder] && [[self window] isMainWindow] && [[self window] isKeyWindow])    {        gradIEnt = [[[NSGradIEnt alloc] initWithcolorsAndLocations:                     [NScolor colorWithDeviceRed:(float)62/255 green:(float)133/255 blue:(float)197/255 Alpha:1.0],0.0,[NScolor colorWithDeviceRed:(float)48/255 green:(float)95/255 blue:(float)152/255 Alpha:1.0],1.0,nil] retain]; //160 80        pathcolor = [[NScolor colorWithDeviceRed:(float)48/255 green:(float)95/255 blue:(float)152/255 Alpha:1.0] retain];    }    else    {        gradIEnt = [[[NSGradIEnt alloc] initWithcolorsAndLocations:                     [NScolor colorWithDeviceRed:(float)190/255 green:(float)190/255 blue:(float)190/255 Alpha:1.0],[NScolor colorWithDeviceRed:(float)150/255 green:(float)150/255 blue:(float)150/255 Alpha:1.0],nil] retain];        pathcolor = [[NScolor colorWithDeviceRed:(float)150/255 green:(float)150/255 blue:(float)150/255 Alpha:1.0] retain];    }        // draw highlight for the visible,selected rows    for (aRow; aRow < anEndRow; aRow++)    {        if([aSelectedRowIndexes containsIndex:aRow])        {            NSRect aRowRect = NSInsetRect([self rectOfRow:aRow],1,4); //first is horizontal,second is vertical            NSBezIErPath * path = [NSBezIErPath bezIErPathWithRoundedRect:aRowRect xRadius:4.0 yRadius:4.0]; //6.0                [path setlinewidth: 2];                [pathcolor set];                [path stroke];            [gradIEnt drawInBezIErPath:path angle:90];        }    }}
总结

以上是内存溢出为你收集整理的objective-c – 在Cocoa的NSTableView中更改突出显示的颜色?全部内容,希望文章能够帮你解决objective-c – 在Cocoa的NSTableView中更改突出显示的颜色?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1031712.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存