UICollectionView 2 Various background colors

I try to avoid white background color on top of my collection cell if the user scrolls down (mostly when it bounces). Thus, on top of my cell, only the background color of the collection is displayed. But, as shown in the picture, I need 2 different colors. For the first section, the background should be blue, so the gap is not white, but blue, and for the remaining sections it should remain white. So all I want is that the white space will turn blue without changing the full background of my version of uicollectionview.

enter image description here

+6
source share
1 answer

You can achieve the desired effect by adding a view at the top of your UICollectionView or UITableView - it will scroll along with the contents and will be displayed as part of the background.

override func viewDidLoad() { super.viewDidLoad() let topView = UIView(frame: CGRect(x: 0, y: -collectionView!.bounds.height, width: collectionView!.bounds.width, height: collectionView!.bounds.height)) topView.backgroundColor = .blackColor() collectionView!.addSubview(topView) } 
+5
source

All Articles