在Custom UICollectionViewCell中更改UILabel的文本颜色

时间:2016-08-24 03:45:32

标签: ios swift uicollectionview uilabel uicollectionviewcell

我一直在尝试更改UILabel中自定义单元格内UICollectionView的文字颜色。目前我正在使用以下代码,它允许我更改Cell的背景颜色,但我只需要更改文本颜色:

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
    {

    //Change background color of selected Cell

    let selectedCell:UICollectionViewCell = collectionView.cellForItemAtIndexPath(indexPath)!

    selectedCell.contentView.backgroundColor = UIColor(red: 102/256, green: 255/256, blue: 255/256, alpha: 0.66)

    }


func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath)
    {

    //Set background color of selected Cell to Clear Color 

    let cellToDeselect:UICollectionViewCell = collectionView.cellForItemAtIndexPath(indexPath)!

    cellToDeselect.contentView.backgroundColor = UIColor.clearColor()

    }

我见过很少的应用程序,其中发线类型的东西在选定的单元格下继续移动。任何人都知道如何实现它?

TIA

2 个答案:

答案 0 :(得分:0)

theLableYouWantToChangeColor.textColor = UIColor.redColor()

正如您所说的自定义UICollectionViewCell,您必须创建自定义UICollectionViewCell并在其中添加UILabel

答案 1 :(得分:0)

您应该有单元格引用并使该标签属性可以从其他类访问并访问并更改它或将颜色对象传递给单元格并仅在那里更改它。 其他检查:参考不应该是零,如果是IBOutlet则应该连接。

相关问题