【Swift Mac开发】修改NSTableView的headerView的背景颜色
// // BMTableViewHeaderCell.swift // BullMan // // Created by Apple on 2021/5/14. // import Foundation class BMTableViewHeaderCell: NSTableHeaderCell { override func draw(withFrame cellFrame: NSRect, in controlView: NSView) { super.draw(withFrame: cellFrame, in: controlView) self.alignment = .center controlView.layer?.backgroundColor = NSColor.white.cgColor } }
使用:
let secondCol = NSTableColumn(identifier: NSUserInterfaceItemIdentifier(rawValue: "secondCol")) secondCol.width = 90 let secondHeaderCell = BMTableViewHeaderCell() secondHeaderCell.alignment = .center secondHeaderCell.stringValue = "合约代码" secondCol.headerCell = secondHeaderCell