Andrew
Andrew

Reputation: 11436

SwiftUI: how to make List view transparent? How to change List view background color?

in case of create the List with Swift UI I have uncontrollable background of the List

enter image description here

Looks like there is absent "native" way to change background color of List background color.

How to make it transparent?

(Answer is below)

Upvotes: 1

Views: 2458

Answers (1)

Andrew
Andrew

Reputation: 11436

the following code makes ALL OF Lists background color transparent:

// Removes background from List in SwiftUI
extension NSTableView {
    open override func viewDidMoveToWindow() {
        super.viewDidMoveToWindow()
        
        backgroundColor = NSColor.clear
        enclosingScrollView!.drawsBackground = false
    }
}

the following code makes ALL OF TextEditors background color transparent:

extension NSTextView {
    open override var frame: CGRect {
        didSet {
            backgroundColor = .clear //<<here clear
            drawsBackground = true
        }
    }
}

Upvotes: 5

Related Questions