xcode - UICollectionViewCell change background color for multiple cells -
i want change cell background color of selected cell anytime select cell changes background color of selected cell , random cell. wrong?
here code:
func collectionview(collectionview: uicollectionview, cellforitematindexpath indexpath: nsindexpath) -> uicollectionviewcell { let cell = collectionview.dequeuereusablecellwithreuseidentifier("cell", forindexpath: indexpath) as! uicollectionviewcell cell.contentview.backgroundcolor = uicolor.orangecolor() return cell } func collectionview(collectionview: uicollectionview, didselectitematindexpath indexpath: nsindexpath){ let cell = colorcollection.cellforitematindexpath(indexpath) cell?.backgroundcolor = uicolor.blackcolor() }
first thing, don't want set cell's background color , not content view's? think should this:
cell.backgroundcolor = uicolor.orangecolor() then can go setting color of selected background view this:
func collectionview(collectionview: uicollectionview, cellforitematindexpath indexpath: nsindexpath) -> uicollectionviewcell { let cell = collectionview.dequeuereusablecellwithreuseidentifier("cell", forindexpath: indexpath) as! uicollectionviewcell cell.backgroundcolor = uicolor.orangecolor() let selectionview = uiview() selectionview.backgroundcolor = uicolor.blackcolor() cell.selectedbackgroundview = selectionview return cell }
Comments
Post a Comment