【问题标题】:How to hide the uiview inside the collection view cell如何隐藏集合视图单元格内的uiview
【发布时间】:2016-08-24 10:30:15
【问题描述】:

我有一个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()
            }                
        }
    }

【问题讨论】:

    标签: ios swift uiview


    【解决方案1】:

    如果您只想设置所选Cell 的颜色,那么您可以像这样使用selectedBackgroundViewCollectionViewCell

    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
    }
    

    注意:无需添加您当前使用的selected 代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 2017-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多