ios - Color of collectionView cell background is different -
i have collectionviewcells colored through storyboard menu like so. (alpha @ 1.0) background color of cell supposed become more transparent when clicked once return normal color on second click however, color on second click different initial color. in the picture provided, top cell still initial color storyboard , bottom 2 after being clicked twice. can see there slight color difference between them. believe problem opacity(the slider @ bottom of first picture) different alpha. used swift line set background color of each cell initial color:
cell.backgroundcolor = uicolor(colorliteralred: 235/255, green: 123/255, blue: 45/255, alpha: 0.8)
i guess since use 80% opacity , 100% alpha initial , 100% opacity , 80% alpha second click, color different. know opacity applies background of cell , not cell whole, opposed alpha decides transparency of whole cell including text in it. wrong here though. question is: how can make cells color of top cell? more specifically, there method can use change opacity of background color of cell instead of alpha of whole cell? maybe like:
cell.backgroundcolor = uicolor(colorliteralred: 235/255, green: 123/255, blue: 45/255, opacity: 0.8)
edit 1:
func collectionview(_ collectionview: uicollectionview, didselectitemat indexpath: indexpath) { if(collectionview == playercollectionview){ let cell = playercollectionview.cellforitem(at: indexpath) as! playercollectionviewcell if cell.isclicked { cell.backgroundcolor = uicolor(colorliteralred: 235/255, green: 123/255, blue: 45/255, alpha: 0.48) cell.isclicked = false } else{ cell.backgroundcolor = uicolor(colorliteralred: 235/255, green: 123/255, blue: 45/255, alpha: 0.8) cell.isclicked = true } playercollectionview.deselectitem(at: indexpath, animated: false) } } func collectionview(_ collectionview: uicollectionview, cellforitemat indexpath: indexpath) -> uicollectionviewcell { if(collectionview == locationcollectionview){ let cell = collectionview.dequeuereusablecell(withreuseidentifier: "locationitem", for: indexpath) as! collectionviewcell cell.locationbutton = cell.viewwithtag(1) as! uibutton cell.settext(text: self.locationarraylist[indexpath.item]) cell.layer.cornerradius = 6 cell.layer.borderwidth = 2 return cell } else { let cell = collectionview.dequeuereusablecell(withreuseidentifier: "playeritem", for: indexpath) as! playercollectionviewcell cell.setupviews(parentsize: int(self.playercollectionview.frame.width), hostuid: self.hostuid, tempusername: playerarraylist[indexpath.item], showkickbutton: false) cell.backgroundcolor = uicolor(colorliteralred: 235/255, green: 123/255, blue: 45/255, alpha: 0.8) cell.layer.cornerradius = 6 cell.layer.borderwidth = 2 return cell } }
Comments
Post a Comment