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

4

12

In OS X 10.10 source lists seem to use the light vibrancy appearance. In the Finder (and in some other third party applications, Things.app for example) the selected item in the source list is indicated by a dark vibrancy appearance. For example, see the Desktop row in the image below.

How can I replicate this behaviour? Do I need to use the delegate methods to specify the table row view,

-outlineView:rowViewForItem:

and attempt custom drawing myself or is there a more straight forward approach? If you make a standard source list UI in Xcode the default highlighting is remain the standard blue rectangle that we have seen in previous version of OS X.

Source list with light vibrancy style, the selected items is darker (using a dark vibrancy style)

Apollyon answered 27/10, 2014 at 20:51 Comment(0)
L
12

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.

Lookeron answered 18/11, 2014 at 9:26 Comment(2)
It works because the vibrancy effect is the default effect for selected items in an outlineView that is not first responder. This is the preferred approach if arrow navigation is better to be performed in other views (case in point, Finder.app, in which navigation through files is expected). However, if the user expects to navigate through your outline view (such as the left bar of Xcode), you should not use this trick.Demurrer
I was able to set the OutlineView's refusesFirstResponder to false to accomplish thisBeverly
H
12

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;
        }
    }

}
Holdback answered 8/11, 2016 at 0:18 Comment(0)
T
7

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

- (BOOL)isEmphasized
{
    return NO;
}
Towhee answered 12/1, 2015 at 14:38 Comment(1)
Works well for me. Note: a subclass is really necessary for this, just allocating a NSTableRowView and setting the isEmphasized property to NO doesn't do the trick.Ellington
T
1

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

Tadio answered 28/10, 2014 at 10:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.