簡體   English   中英

NSTableRowView backgroundColor僅在子視圖周圍繪制

[英]NSTableRowView backgroundColor only draws around subviews

在側邊欄樣式輪廓視圖中,當我在傳遞給outlineView:didAddRowView:row:的行視圖outlineView:didAddRowView:row: backgroundColor設置為白色時,它僅繪制該行的內容。 在子視圖下,常規背景仍然顯示。 我如何使整行都繪制成白色?

行截圖

正如Eugene Mankovski指出的那樣,您必須使視圖層成為后盾。 此代碼段將為您提供幫助。

extension NSView {

     var customBackgroundColor: NSColor? {
        get {
            if let colorRef = self.layer?.backgroundColor {
                return NSColor(CGColor: colorRef)
            } else {
                return nil
            }
        }
        set {
            self.wantsLayer = true
            self.layer?.backgroundColor = newValue?.CGColor
        }
    }
}

並以這種方式訪問​​它。

self.yourView.customBackgroundColor = NSColor.lightGrayColor()

暫無
暫無

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

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