如何在集合视图单元格中隐藏uiview

时间:2016-08-24 10:30:16

标签: ios swift uiview

我有一个colelctionViewCell,其中一个标签和一个UIView。我所做的是,在我的自定义集合视图单元格中,我保留了一种方法。也就是说:如果用户按下集合视图单元格,那么只有UIView的颜色会被选中,否则它将是其他颜色。

但我需要的是最初我需要隐藏我的view。而对于第一个自定义单元格,只有我的uiview应该显示。怎么做??

@IBOutlet weak var ProductCatg: UILabel!                
@IBOutlet weak var highLightBar: UIView!

    override var selected: Bool {
        didSet {                                               
            if selected {
                highLightBar.backgroundColor = UIColor.yellowColor()
            } else {
                highLightBar.backgroundColor = UIColor.clearColor()
            }                
        }
    }

1 个答案:

答案 0 :(得分:0)

如果您只想设置所选Cell的颜色,那么您可以使用此selectedBackgroundView的{​​{1}}。

CollectionViewCell

注意:无需添加当前使用的func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCellWithReuseIdentifier(KCollectionViewCellIdentifier, forIndexPath: indexPath) as! collectionViewCell let selectedview = UIView(frame: cell.contentView.bounds) selectedview.backgroundColor = UIColor.yellowColor() cell.selectedBackgroundView = selectedview return cell } 代码。

相关问题