// // KMNTableHeaderCellView.swift // PDF Reader Pro // // Created by User-Tangchao on 2024/11/7. // import Cocoa class KMNTableHeaderCellView: NSTableCellView { private var contentBox: NSBox = { let box = NSBox() box.boxType = .custom box.titlePosition = .noTitle box.contentViewMargins = .zero box.borderWidth = 0 return box }() private var titleLabel_: NSTextField = { let view = NSTextField(labelWithString: "") return view }() private var leftVLine_: NSView = { let view = NSView() return view }() private var rightVLine_: NSView = { let view = NSView() return view }() private var bottomLine_: NSView = { let view = NSView() return view }() private var button_: NSButton = { let view = NSButton() view.isBordered = false view.title = "" return view }() var titleLabel: NSTextField { get { return self.titleLabel_ } } var leftLine: NSView { get { return self.leftVLine_ } } var rightLine: NSView { get { return self.rightVLine_ } } var bottomLine: NSView { get { return self.bottomLine_ } } var itemClick: KMCommonClickBlock? override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) // Drawing code here. } convenience init() { self.init(frame: .init(x: 0, y: 0, width: 40, height: 40)) initSubviews() } override func awakeFromNib() { super.awakeFromNib() initSubviews() } func initSubviews() { addSubview(contentBox) contentBox.km_add_inset_constraint() contentBox.contentView?.addSubview(leftVLine_) contentBox.contentView?.addSubview(titleLabel_) contentBox.contentView?.addSubview(rightVLine_) contentBox.contentView?.addSubview(bottomLine_) leftVLine_.km_add_leading_constraint() leftVLine_.km_add_top_constraint(constant: 4) leftVLine_.km_add_bottom_constraint(constant: -4) leftVLine_.km_add_width_constraint(constant: 0.5) titleLabel_.km_add_leading_constraint(constant: 8) titleLabel_.km_add_centerY_constraint() rightVLine_.km_add_trailing_constraint() rightVLine_.km_add_top_constraint(constant: 4) rightVLine_.km_add_bottom_constraint(constant: -4) rightVLine_.km_add_width_constraint(constant: 0.5) bottomLine_.km_add_bottom_constraint(constant: 0) bottomLine_.km_add_leading_constraint(constant: 0) bottomLine_.km_add_trailing_constraint(constant: 0) bottomLine_.km_add_height_constraint(constant: 1) contentBox.fillColor = .clear contentBox.addSubview(button_) button_.bounds = contentBox.contentView?.bounds ?? .zero button_.autoresizingMask = [.width, .height] button_.target = self button_.action = #selector(_buttonAction) } // MARK: - Private Methods @objc private func _buttonAction() { self.itemClick?(1) } }