Coloring rows in View based NSTableview

后端 未结 4 1525
清酒与你
清酒与你 2021-02-12 17:26

I have a view based nstableview. I want to color entire row based on some condtion for which I have used code below

- (NSTableRowView *)tableView:(NSTableView *)         


        
4条回答
  •  星月不相逢
    2021-02-12 18:16

    I re-wrote the layer approach. In Swift 3.2

    func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
    
        let greenCell = self.tableview.make(withIdentifier: "green", owner: self)
        let layer:CALayer = CALayer()
        layer.backgroundColor = NSColor.green.cgColor
    
        greenCell?.wantsLayer = true
        greenCell?.layer = layer
    
        return greenCell
    
    }
    

    Don't forget to change the Identifier of the cell according to your storyboard, and in the code identifier "green". And surely, the background color if you want.

提交回复
热议问题