Change selection color on view-based NSTableView

前端 未结 13 2067
别跟我提以往
别跟我提以往 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:20

    Okay, So I do know that it already has an accepted answer, but for anyone like me working with an NSOutlineView and has .selectionHighlightStyle = .sourceList can use this code to make the selection grey. This method will not flicker when changing the selection and will also stay grey if the app is minimised.

    NSTableView/NSOutlineView Delegate:

    func outlineView(_ outlineView: NSOutlineView, rowViewForItem item: Any) -> NSTableRowView?
    {
         let row : CustomRowView = CustomRowView.init()
         row.identifier = "row"
    
         return row
    }
    

    And then create a new CustomRowView.swift file with this:

    class CustomRowView : NSTableRowView
    {
        override var isEmphasized: Bool {
            get { return self.isEmphasized }
            set(isEmp) { self.isEmphasized = false }
        }
    }
    

    This will keep the selection grey at all times.

提交回复
热议问题