如何将自定义样式应用于NSTableHeaderView? [英] How to apply custom styling to NSTableHeaderView?

查看:414
本文介绍了如何将自定义样式应用于NSTableHeaderView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我要寻找一个自定义外观的NSTableView.我已经成功地将NSTableRowViewNSTextFieldCell进行了子类化,以实现我想要的外观,但是我正在努力摆脱标头的默认样式.我似乎可以调整其框架,但是我不确定其余默认样式来自何处.

So I am going for a custom looking NSTableView. I've already successfully subclassed NSTableRowView and NSTextFieldCell to achieve the look I'm going for, however I'm struggling of getting rid of the default styling for the header. I seem to be able to tweak its frame, however I'm not sure where the rest of the default styling is coming from.

如屏幕截图所示,红色区域是headerView的增大框.我正在使用它的CALayer设置颜色,但是如何更改内部内容不属于我...

As you see on the screenshot the red area is the increased frame of the headerView. I'm using its CALayer to set the colour, however how to change the contents inside is beyond me...

这是我在ViewController的viewDidLoad中所做的

Here's what I'm doing in the viewDidLoad of my ViewController

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.delegate = self
    tableView.dataSource = self
    tableView.wantsLayer = true
    tableView.headerView?.frame = NSMakeRect(0, 0, (tableView.headerView?.frame.width)!, 32.00)
    tableView.headerView?.wantsLayer = true
    tableView.headerView?.layer?.backgroundColor = NSColor.red.cgColor
}

我也尝试了对NSTableHeaderView进行子类化,但是就我可以进行的自定义而言,此类似乎非常受限制...

I've also tried subclassing NSTableHeaderView, however this class seems to be extremely limited in terms of the customizations I can make...

有什么帮助吗?

推荐答案

表视图基于视图,但标头不是,并且标头单元格仍为类NSTableHeaderCell.使用NSTableColumn的属性headerCell.您可以设置像attributedStringValuebackgroundColor这样的单元格属性,或用NSTableHeaderCell子类的实例替换单元格并覆盖其中的draw方法之一.

The table view is view based but the header isn't and the header cells still are class NSTableHeaderCell. Use NSTableColumn's property headerCell. You can set the cell's properties like attributedStringValue and backgroundColor or replace the cells by instances of a subclass of NSTableHeaderCell and override one of the draw methods.

这篇关于如何将自定义样式应用于NSTableHeaderView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆