Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionView 2 Different Background Colors

I try to avoid the white background color on top of my collectionview cell if the user scrolls down (basicly when it bounced). So on top of my cell is only the collectionview background color visible. But as shown in the picture I need 2 different colors. For the first section the background should be blue so the gap isn't white but blue and for the other sections it should remain white. So all I want is that the gap in white will become blue without changing the complete backgroundcolor of my uicollectionview.

enter image description here

like image 966
Tobias Avatar asked Jul 22 '16 11:07

Tobias


1 Answers

You can achieve the desired effect by adding a view to the top your UICollectionView or UITableView - it will be scrolled along with the content and will appear 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)
}
like image 178
maxkonovalov Avatar answered Nov 18 '22 05:11

maxkonovalov