Transparent NSCollectionView Background

前端 未结 3 530
滥情空心
滥情空心 2021-01-04 23:53

I\'m again struggling with setting NSViews background colors to transparent. I have a NSCollectionView as part of NSClipView which is part of a

3条回答
  •  醉话见心
    2021-01-05 00:44

    To make clear background for NSScrollView, the best option in Swift 4.2 is "Not draw a background". Let's get to view a programmatically example:

    let scrollView = NSScrollView()
    scrollView.drawsBackground = false
    scrollView.contentView.drawsBackground = false
    

    NSCollectionView has background for sections, so you need to specify colors for sections

    let collectionView = NSCollectionView()
    collectionView.backgroundColors = [.clear]
    

    If you set backgroundColors to nil or to empty array, the background color is set by default to white.

    If you set a background view for NSCollectionView, this array is ignored

    You could try to put a NSView with frame zero as a backgroundView for NSCollectionView

提交回复
热议问题