我想点击UICollectionView的单元格,单元格变为半透明。
- (void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
GLEpisodeCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:[GLEpisodeCell identifier] forIndexPath:indexPath];//GLEpisodeCell is subclass of UICollectionViewCell
cell.alpha=0.5;
cell.contentView.alpha=0.5;
}
但这不起作用。细胞仍然不透明。
尝试这样可能会对你有所帮助。
- (void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
GLEpisodeCell *cell=[collectionView cellForItemAtIndexPath:indexPath];//GLEpisodeCell is subclass of UICollectionViewCell
cell.alpha=0.5;
cell.contentView.alpha=0.5;
}
布局设置alpha。要覆盖,请将其放在您的单元格子类中:
override func apply(_ layoutAttributes: UICollectionViewLayoutAttributes) {
alpha = 0.5
}
您还必须为新创建的单元格设置alpha。
cell.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.5];
这将创建单元格的背景颜色为50%的透明度,而不是单元格的内容。如果你想要那么你想要的那样。 cell.backgroundView.alpha = 0.5;