【发布时间】:2015-10-25 05:05:56
【问题描述】:
我有一个 UICollectionView,一切正常,但是,有一件事情我无法处理(我不知道如何处理),我有一个单元格集合,可以查看用户需要滚动的所有单元格像往常一样向下或向上。
当用户选择单元格时,内容变为“红色”,红色为“选中”单元格,黑色为“未选中”单元格或正常状态。
当所选单元格落在导航栏或标签栏后面时,该单元将失去“红色”并再次变为黑色,如“未选择”。
如何在 uicollectionview 滚动时单元格落后时保持“红色”?
override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let cell = collectionView.cellForItemAtIndexPath(indexPath)
let icon = cell!.viewWithTag(10) as? UIImageView
icon!.image = icon!.image! .imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
icon!.tintColor = UIColor.redColor()
let label = cell!.viewWithTag(100) as? UILabel
label?.textColor = UIColor.redColor()
//print("Seleccionado")
}
override func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) {
let cell = collectionView.cellForItemAtIndexPath(indexPath)
cell!.contentView.backgroundColor = nil
cell!.contentView.layer.borderColor = nil
let icon = cell!.viewWithTag(10) as? UIImageView
icon!.image = icon!.image! .imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate)
icon!.tintColor = UIColor.blackColor()
let label = cell!.viewWithTag(100) as? UILabel
label?.textColor = UIColor.lightGrayColor()
//print("Unselect")
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! ObjectosCollectionViewCell
cell.objectoNameLabel.text = objectosData[indexPath.row]
cell.objectoNameLabel.textColor = UIColor.lightGrayColor()
cell.objectoImageView.image = UIImage(named:objectosImage[indexPath.row])
return cell
}
谢谢
【问题讨论】:
标签: ios swift uicollectionview uicollectionviewcell