ios - UICollectionview cells change when scrolling -


my uicollectionview looks this:

enter image description here

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.

enter image description here

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:

  1. set uicollectionviewcell's cliptobounds true
  2. set uiimageview's cliptobounds true
  3. set aspectratio of imageview = 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:

  1. set aspectratio of imageview = 1:1 in storyboard
  2. from code, remove:

imageview.layer.maskstobounds = true

  1. in storyboard: set uiimageview's cliptobounds true

4. screenshot:

enter image description here

let me know if need other kind of regarding code.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -