1

This question is a addition of this topic: tableview image content selection color

All works fine, but one little thing bothers me. This is the result:

enter image description here

You can see that the default color of the image is grey. If you select a row, the image should change the color to white - it works! but you can see a short delay before it will change the color (I hope you see what I mean)

Can I optimize it?

This is my Code:

// Change Color of Image
    func tintedImage(_ image: NSImage, tint: NSColor) -> NSImage {
        guard let tinted = image.copy() as? NSImage else { return image }
        tinted.lockFocus()
        tint.set()

        let imageRect = NSRect(origin: NSZeroPoint, size: image.size)
        imageRect.fill(using: .sourceAtop)

        tinted.unlockFocus()
        return tinted
    }


func outlineViewSelectionIsChanging(_ notification: Notification) {

   if lastSelectedRow != nil {
      let view = myOutlineView.view(atColumn: 0, row: lastSelectedRow!, makeIfNecessary: true) as! CustomCell
                    view.imgView.image = self.tintedImage(NSImage(named: NSImage.Name(rawValue: "MyImage"))!, tint: NSColor.grey)
                }

                lastSelectedRow = myOutlineView.selectedRow

    }

 func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? {


            let view = outlineView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "Cell"), owner: self) as? CustomCell

            if lastSelectedRow == outlineView.selectedRow {
                view?.imgView.image = self.tintedImage(NSImage(named: NSImage.Name(rawValue: "MyImage"))!, tint: NSColor.white)
            } else {
                view?.imgView.image = self.tintedImage(NSImage(named: NSImage.Name(rawValue: "MyImage"))!, tint: NSColor.grey)
            }



            return view
}
Trombone0904
  • 4,132
  • 8
  • 51
  • 104

0 Answers0