[英]NSTableRowView backgroundColor only draws around subviews
正如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.