Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CollectionView background clearColor not working

I'm developing a small collectionview 'framework' to behave like a browser tab bar (think chrome) on the iPad. The code is all done, custom flow layout, reordering, and so on and is organized as so :

• TabBarCollectionViewController .h/.m/.xib contains the high logic of the collection view (delegates + datasource methods). I have the xib to configure the collectionView settings and set the custom flow layout (I could do this programmatically, but oh well it's easier that way).

• CustomFlowLayout .h/.m (subclass of flow layout)

• TabBarCell .h/.m/.xib (subclass of collectionviewcell)

Then I'm adding the TabBarCVC as a childViewController on my main viewController (this viewController has many childViewController and subviews) and then as a subview. At this point all is working fiiiiine.

Now the problem, it's so stupid i can't believe i haven't found a way to do this, the backgroundColor of the collectionView is not settable to clearColor. I can put it in gray or whatever color, but that it doesn't support transparency. The cell background color is also clear and does work.

I need the collectionView to be transparent to show the texture on the main view behind. Any insight would be much appreciated, or perhaps i'll fill my first radar to apple.

If i can't find any solution i'll just add the 'screenshot' of the texture supposed to be behind the collectionView and add it as a imageView in the collectionView's backgroundView.

like image 327
nebuto Avatar asked May 15 '13 16:05

nebuto


4 Answers

In my case I had the background color in the storyboard set to Default. This caused it to have a black background. Changing it to Clear Color worked.

enter image description here

like image 124
Kyle Robson Avatar answered Nov 14 '22 19:11

Kyle Robson


Try setting the color to clear and the background view to an empty view like so...

self.collectionView.backgroundColor = [UIColor clearColor];
self.collectionView.backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
like image 50
Fogmeister Avatar answered Nov 14 '22 20:11

Fogmeister


Ok so i'm feeling pretty stupid now. I left an empty UIView behind, acting as a container for the collectionView for a test. I simply forgot to remove it, all is working fine with a nice clearColor now...

like image 10
nebuto Avatar answered Nov 14 '22 18:11

nebuto


Watch out when setting UICollectionViews Background Color in Storyboard:

The initially selected value Default is Black (counterintuitively).
You have to explicitly select Clear Color for the View to be transparent.

Also note that the Preview in Storyboard immediately changes when this is done 'right'...

like image 7
DaniEll Avatar answered Nov 14 '22 18:11

DaniEll