如何在 UICollectionView 上设置渐变固定背景? [英] How could I set gradient fixed background on UICollectionView?

查看:29
本文介绍了如何在 UICollectionView 上设置渐变固定背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了以下代码.

CAGradientLayer* collectionRadient = [CAGradientLayer layer];
collectionRadient.bounds = self.collectionView.bounds;
collectionRadient.anchorPoint = CGPointZero;
collectionRadient.colors = [NSArray arrayWithObjects:(id)[startColor CGColor],(id)[endColor CGColor], nil];
[self.collectionView.layer insertSublayer:collectionRadient atIndex:0];

但它绘制在包含图像的单元格上.所以没有显示单元格.

But it drawn on cells included images. so cell was not shown.

我想在 Cells 下绘制 UICollectionView 的渐变背景,并在视图滚动时修复它.请告诉我.

I want to draw gradient background of UICollectionView under Cells and fixed it when view scrolled. Let me know Please.

推荐答案

试试这个...你必须分配一个视图才能使用背景视图.

Try this... You have to assign a view to use background view.

CAGradientLayer* collectionGradient = [CAGradientLayer layer];
collectionGradient.bounds = self.view.bounds;
collectionGradient.anchorPoint = CGPointZero;
collectionGradient.colors = [NSArray arrayWithObjects:(id)[[UIColor redColor] CGColor],(id)[[UIColor greenColor] CGColor], nil];
UIView *vv = [[UIView alloc] init];
vview.backgroundView = vv;
[vview.backgroundView.layer insertSublayer:collectionGradient atIndex:0];

这篇关于如何在 UICollectionView 上设置渐变固定背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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