Add Border to Custom CollectionView

How to add border to UICollectionView cells that uses custom UICollectionViewFlowLayout ? When I override the UICollectionView layout, the cell borders are β€œdeleted”. How can I set the boundaries correctly? Thanks!

+6
source share
1 answer

I'm not sure how you want your border to look, but whenever I need a quick border around a view, I usually use the following:

 var view = UIView(frame: frame) view.layer.borderWidth = 1 view.layer.borderColor = UIColor.blackColor().CGColor 

Update Swift 3

 view.layer.borderColor = UIColor.black.cgColor 

Perhaps you can apply this to your collection view cell or create your own class that sets these values ​​after initialization.

Either this, or you can set the cell size so that spaces between cells serve as borders and set minimumLineSpacing and minimumInteritemSpacing in your custom stream layout implementation.

+18
source

Source: https://habr.com/ru/post/987310/


All Articles