Swift - CollectionViewCell Border Bug or Incomplete

I have a collectionViewCell which appears to be weird. The left,right vertical borders are missing, I don't know what I'm missing. Can you help me guys? Thanks!

 public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! profileServicesCell

    // Card border
    cell.backgroundColor = UIColor.white
    cell.layer.borderWidth = 1.0
    cell.layer.borderColor = UIColor.lightGray.cgColor

    // Cell Content
    cell.profileServiceName.text = profileServicesName[indexPath.row]
    cell.profileServiceIcon.image = UIImage(named: profileServicesIcon[indexPath.row])

    return cell
}

Attached images for reference :

StoryBoard Image

StoryBoard Image

Simulator/RunTime

enter image description here

1 answer

  • answered 2018-08-15 10:14 killvak

    maybe the problem that you didn't specify any size for your cell try this out :

    extension Your_Class :  UICollectionViewDelegateFlowLayout {
    
        func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        let width = self.view.frame.width * 0.4  // or whatever width you like 
        let height = width / 2 // or whatever height you like 
        return CGSize(width: width, height: height)
      }
    
       }