title: UICollectionview cells change when scrolling
body: <p>My UICollectionview looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/mP3JB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mP3JB.png" alt="enter image description here"></a></p>
  
  <p>My UICollectionviewCell contains an Image, and by setting the corner radius property I am trying to make it round, but this is the result. The same goes for my Image in my HeaderView.</p>
  
  <p>Moreover do my UICollectionviewCells change when I scroll and randomly change appearance, by some finally being round, some even diamond shaped and some icons being black.</p>
  
  <p><a href="https://i.stack.imgur.com/mIQfQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mIQfQ.png" alt="enter image description here"></a></p>
  
  <p>Here is the code I'm using for the CollectionviewCell:</p>
  
  <pre><code>func collectionView(_ collectionView: UICollectionView,
                               cellForItemAt indexPath: IndexPath) -&gt; 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
  }
  </code></pre>
  
  <p>Here is the code of my HeaderView:</p>
  
  <pre><code>//make the profileImageView round
      imageview.layer.masksToBounds = true
      imageview.layer.cornerRadius = imageview.frame.height/2
      imageview.layer.borderWidth = 4
      imageview.layer.borderColor = UIColor.white.cgColor
  </code></pre>