【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

 

 

posted @ 2021-05-14 13:43  Mr·Xu  阅读(371)  评论(0编辑  收藏  举报