Change selection color on view-based NSTableView

前端 未结 13 2107
别跟我提以往
别跟我提以往 2020-12-07 19:11

Standard highlighting color in OS X applications is blue.

Is it possible to change it to another color, e.g. gray?

Note that I am using the new view-based

13条回答
  •  感动是毒
    2020-12-07 19:29

    When using Swift you can do this on 10.10 for view based Cells

    Subclass the NSTableCellView and implement this:

    //override to change background color on highlight
    override var backgroundStyle:NSBackgroundStyle{
        //check value when the style was setted
        didSet{
            //if it is dark the cell is highlighted -> apply the app color to it
            if backgroundStyle == .Dark{
                self.layer!.backgroundColor = yourColor
            }
            //else go back to the standard color
            else{
                self.layer!.backgroundColor = NSColor.clearColor().CGColor
            }
        }
    }
    

    Note that the NSTableView highlight style must be set to Regular if it is on SourceList it will cause some strange clipping.

    This is not the cleanest solution but it works good on yosemite

提交回复
热议问题