// // AccountBenefitCellView.swift // PDF Reader Pro // // Created by User-Tangchao on 2024/10/30. // import Cocoa class AccountBenefitCellView: NSTableCellView { private lazy var contentBox_: NSBox = { let view = NSBox() view.boxType = .custom view.titlePosition = .noTitle view.contentViewMargins = .zero view.borderWidth = 0 return view }() private lazy var titleLabel_: NSTextField = { let view = NSTextField(labelWithString: "") view.font = .systemFont(ofSize: 16) view.textColor = KMAppearance.titleColor() return view }() private lazy var hotIv_: NSImageView = { let view = NSImageView() view.image = NSImage(named: "KMImageNameAccountBenefitHot") return view }() private lazy var subTitleLabel_: NSTextField = { let view = NSTextField(labelWithString: "") return view }() private lazy var buttonBox_: NSBox = { let view = NSBox() view.boxType = .custom view.titlePosition = .noTitle view.contentViewMargins = .zero view.borderWidth = 0 return view }() private lazy var button_: NSButton = { let view = NSButton() view.isBordered = false return view }() var titleLabel: NSTextField { get { return self.titleLabel_ } } var subTitleLabel: NSTextField { get { return self.subTitleLabel_ } } var hotIv: NSImageView { get { return self.hotIv_ } } 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: 200, height: 126)) self.initSubviews() self.initDefaultValue() } override func awakeFromNib() { super.awakeFromNib() self.initSubviews() self.initDefaultValue() } func initSubviews() { self.addSubview(self.contentBox_) self.contentBox_.contentView?.addSubview(self.titleLabel_) self.contentBox_.contentView?.addSubview(self.hotIv_) self.contentBox_.contentView?.addSubview(self.subTitleLabel_) self.contentBox_.contentView?.addSubview(self.buttonBox_) self.buttonBox_.contentView?.addSubview(self.button_) self.contentBox_.km_add_inset_constraint(inset: NSEdgeInsetsMake(10, 10, 10, 10)) self.titleLabel_.km_add_leading_constraint(constant: 20) self.titleLabel_.km_add_top_constraint(constant: 23) self.hotIv_.km_add_size_constraint(size: .init(width: 30, height: 16)) self.hotIv_.km_add_centerY_constraint(equalTo: self.titleLabel_) self.hotIv_.km_add_leading_constraint(equalTo: self.titleLabel_, attribute: .trailing, constant: 2) self.subTitleLabel_.km_add_leading_constraint(constant: 20) self.subTitleLabel_.km_add_top_constraint(equalTo: self.titleLabel_, attribute: .bottom, constant: 5) self.buttonBox_.km_add_right_constraint(constant: -20) self.buttonBox_.km_add_bottom_constraint(constant: -24) self.buttonBox_.km_add_height_constraint(constant: 32) self.button_.km_add_leading_constraint(constant: 24) self.button_.km_add_right_constraint(constant: -20) self.button_.km_add_centerY_constraint() } func initDefaultValue() { self.contentBox_.cornerRadius = 8 self.contentBox_.fillColor = NSColor(hex: "#F9F9FD") self.buttonBox_.cornerRadius = 4 self.buttonBox_.fillColor = KMAppearance.themeColor() self.button_.title = NSLocalizedString("Buy Now", comment: "") self.button_.setTitleColor(.white) self.button_.target = self self.button_.action = #selector(buttonAction) } @objc func buttonAction() { self.itemClick?(1) } }