簡體   English   中英

在NSTableCellView上設置背景顏色

[英]Set Background colour on NSTableCellView

我試圖在NSTableCellView上設置背景顏色,但似乎沒有辦法做到這一點。

因此,必須有另一種方法來實現這一點,我不知道,所以,如果有人能夠啟發我,我會非常感激!

謝謝!

NSTableCellView NSViewNSView CALayerCALayer backgroundColor 所以...

myTableCellView.wantsLayer = YES;  // make the cell layer-backed
myTableCellView.layer.backgroundColor = [[NSColor redColor] CGColor]; // or whatever color you like

您需要將NSColor對象轉換為CGColor結構:

self.layer.backgroundColor = [[NSColor redColor] CGColor];

對於Swift 3,基於Caleb的答案,這對我有用:

cell.wantsLayer = true
cell.layer?.backgroundColor = NSColor.red.cgColor 

我花了很長時間才找到這個問題和答案,我非常感激。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM