UICollectionView 2 种不同的背景颜色 [英] UICollectionView 2 Different Background Colors

查看:57
本文介绍了UICollectionView 2 种不同的背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户向下滚动(基本上是在它弹起时),我会尽量避免我的 collectionview 单元格顶部的白色背景颜色.所以在我的单元格顶部只有 collectionview 背景颜色可见.但如图所示,我需要 2 种不同的颜色.对于第一部分,背景应该是蓝色,所以间隙不是白色而是蓝色,对于其他部分,它应该保持白色.所以我想要的是,在不改变我的 uicollectionview 的完整背景色的情况下,白色的间隙会变成蓝色.

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.

推荐答案

你可以通过在 UICollectionView 或 UITableView 的顶部添加一个视图来达到预期的效果——它会随着内容一起滚动并作为视图的一部分出现背景.

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)
}

这篇关于UICollectionView 2 种不同的背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆