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!
Asked
Active
Viewed 1.7k times
10

Aнгел
- 1,361
- 3
- 17
- 32
1 Answers
25
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.

ErasmoOliveira
- 1,416
- 2
- 20
- 40

skim
- 2,267
- 2
- 16
- 17
-
1Simple and worked great. You can just add it to a cell and there you go. – Rob Norback Sep 10 '15 at 20:16