Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add border to custom CollectionView

How can I add border to UICollectionView's cells which uses a custom UICollectionViewFlowLayout? When I override UICollectionView's flow layout, cell borders are "removed". how can I set borders properly? Thank you!

like image 532
Aнгел Avatar asked May 15 '15 22:05

Aнгел


1 Answers

I'm not sure how you want your border to look like, 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

You can either probably apply this to your collection view cell or create a custom class that sets these values after initialization.

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

like image 99
skim Avatar answered Sep 29 '22 11:09

skim