ios - UICollectionview cells change when scrolling -
my uicollectionview looks this:
my uicollectionviewcell contains image, , setting corner radius property trying make round, result. same goes image in headerview.
moreover uicollectionviewcells change when scroll , randomly change appearance, being round, diamond shaped , icons being black.
here code i'm using collectionviewcell:
func collectionview(_ collectionview: uicollectionview, cellforitemat indexpath: indexpath) -> uicollectionviewcell { //1 let cell = collectionview.dequeuereusablecell(withreuseidentifier: "collectionviewcell", for: indexpath) as! collectionviewcell cell.imageview.layoutifneeded() cell.imageview.layer.maskstobounds = true cell.backgroundcolor = uicolor.clear cell.imageview.tintcolor = uicolor.white cell.imageview.layer.borderwidth = 2 cell.imageview.layer.bordercolor = uicolor.white.cgcolor cell.imageview.layer.cornerradius = cell.frame.width/2 let icon = categories[indexpath.item]?.image cell.namelabel.text = categories[indexpath.item]?.name cell.namelabel.textcolor = uicolor.white cell.imageview.image = icon let selected = categories[indexpath.item]?.selected if selected! { cell.isselected = true collectionview.selectitem(at: indexpath, animated: true, scrollposition: .centeredhorizontally) cell.imageview.backgroundcolor = uicolor.white cell.imageview.tintcolor = colors.colorbottom } return cell } here code of headerview:
//make profileimageview round imageview.layer.maskstobounds = true imageview.layer.cornerradius = imageview.frame.height/2 imageview.layer.borderwidth = 4 imageview.layer.bordercolor = uicolor.white.cgcolor
1. make imageview in uicollectionviewcell round, in storyboard:
- set
uicollectionviewcell'scliptoboundstrue - set
uiimageview'scliptoboundstrue - set
aspectratioofimageview=1:1
remove these 2 line cellforitemat
cell.imageview.layoutifneeded() cell.imageview.layer.maskstobounds = true 2. below line must responsible icons becoming black
cell.imageview.tintcolor = colors.colorbottom check if changing selected status in categories array whenever cell selected?
3. in headerview:
- set
aspectratioofimageview=1:1instoryboard - from code, remove:
imageview.layer.maskstobounds = true
- in
storyboard: setuiimageview'scliptoboundstrue
4. screenshot:
let me know if need other kind of regarding code.



Comments
Post a Comment