Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在集合视图单元格中隐藏uiview_Ios_Swift_Uiview - Fatal编程技术网

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

Ios 如何在集合视图单元格中隐藏uiview,ios,swift,uiview,Ios,Swift,Uiview,我有一个带有一个标签的colelctionViewCell,还有一个UIView。我所做的是,在我的自定义集合视图单元格中,我保留了一个方法。也就是说:如果用户按下集合视图单元格,则只有该视图的颜色会改变,否则它将是其他颜色 但我首先需要隐藏我的视图。对于第一个自定义单元格,应该只显示我的uiview。怎么做 @IBOutlet weak var ProductCatg: UILabel! @IBOutlet weak var highLightBar: UIVi

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

但我首先需要隐藏我的
视图
。对于第一个自定义单元格,应该只显示我的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()
            }                
        }
    }

如果您只想设置所选
单元格的颜色
,则可以像这样使用
CollectionViewCell
selectedBackgroundView

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
}
注意:无需添加您当前正在使用的
选定的
代码