How to get the source lists selection highlight to use the Dark Vibrancy appearance in OS X 10.10?

╄→尐↘猪︶ㄣ 提交于 2019-11-30 03:54:49

After playing around for a while I found a way to accomplish this. It turned out that I would get the "Finder highlight" style when using NSTableViewSelectionHighlightStyleSourceList and clicking outside my NSOutlineView. So I figured it would stay that way if you refuse making it first responder.

Simply make your NSOutlineView a subclass and override this method:

-(BOOL)acceptsFirstResponder{     return NO; } 

It works, but with some downsides. For example, using arrow keys in the NSOutlineView will no longer work. I downloaded the Things app, and it does not allow use of arrow keys either, so it's very likely that this is how they are doing it. If anyone finds a better way, please post it.

Here is the Swift equivalent :

func outlineView(_ outlineView: NSOutlineView, rowViewForItem item: Any) -> NSTableRowView? {     return CustomTableRowView(frame: NSZeroRect); } 

And the subclass of NSTableRowView

import Cocoa  class CustomTableRowView: NSTableRowView {      override var isEmphasized: Bool {         set {}         get {             return false;         }     }  } 

If you would like to keep arrow keys working, you can subclass NSTableRowView and override the following method:

- (BOOL)isEmphasized {     return NO; } 
Thomas Krajacic

I am not sure, this is "Dark Vibrancy".

I would rather try setting the background color to something like "Alternate Selected Control Text Color"

Have a look at an NSTextField in InterfaceBuilder. there are many "Control Text" colors, which have a special appearance on visual effect views.

and for setting the selection color see this answer (untested): NSTableview Change the highlight colour

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!