Transparent Background NSCollectionView

I am trying again to set the transparency of the background colors of NSViews. I have NSCollectionViewas part NSClipView, which is part NSScrollview. Mine MainViewControllerhas a way out collectionView. With the addition of two lines of code and after compilation, the background is sometimes transparent, but in most cases not:

view.wantsLayer = true
collectionView.layer?.backgroundColor = NSColor.clear.cgColor

I also tried to select / deselect the "Draw background" property NSScrollviewin IB without any effects. What I miss here.

+7
source share
3 answers

Well, after a long phase of trial and error, I found a solution, at least for myself. For proper behavior, you need to set two background colors:

  1. NSScrollView:

enter image description here

  1. NSCollectionView:

enter image description here

. , , . ScrollView CollectionView .

+5

NSCollectionView "" @JFS , , , , Scrollview CollectionView :

cvScrollView.backgroundColor = NSColor.clear
collectionView.backgroundColors = [NSColor.clear]
+5

NSScrollView, Swift 4.2 " ". :

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

NSCollectionView ,

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

backgroundColors nil , .

If you set the background view to NSCollectionView, this array is ignored

You can try to put NSViewwith zero framein quality backgroundViewforNSCollectionView

0
source

Source: https://habr.com/ru/post/1668887/


All Articles