Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionView and cell separators? Is this something to be handled by supplementary views? Decoration views? Within the cell itself?

I'm a little new to UICollectionView, and I'm trying to build a vertical list of items with only one column/only one item per row.

Between each UICollectionViewCell I want to have a divider line, similar to UITableView's separator. (No I can't use UITableView for this purpose due to other reasons.)

How should I be accomplishing this? Simply adding a 1px high UIView to each cell? Use a "supplementary view"? Use a "decoration view"? I'm lost and no tutorials seem to indicate what would be best here.

It seems ridiculous to have to reimplement the full UICollectionViewLayout to have some lines, but throwing the line in each cell seems sloppy. What should I be doing?

like image 813
Doug Smith Avatar asked Jun 29 '15 18:06

Doug Smith


People also ask

How does UICollectionView work?

UICollectionView makes adding custom layouts and layout transitions, like those in Photos, simple to build. You're not limited to stacks and grids because collection views are customizable. You can use them to make circle layouts, cover-flow style layouts, Pulse news style layouts and almost anything you can dream up!

What is a UICollectionView?

An object that manages an ordered collection of data items and presents them using customizable layouts.

How do I manage a collection VIEW cell in Swift?

Create a new iOS app project Select the Main storyboard from the file browser. Add a CollectionView by pressing command shift L to open the storyboard widget window. Drag the collectionView onto the main view controller.

What is Uicollectionreusableview?

A view that defines the behavior for all cells and supplementary views presented by a collection view.


1 Answers

I think the problem is with connection flow layout

You can write this code in viewDidLoad

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
//You can provide vertical


[flowLayout setMinimumInteritemSpacing:0.0f];
[flowLayout setMinimumLineSpacing:0.0f];
[self.pictureCollectionView setPagingEnabled:YES];
[self.pictureCollectionView setCollectionViewLayout:flowLayout];
[self.pictureCollectionView setBackgroundColor:[UIColor whiteColor]];

Set this as your flow layout. I once made a slide show with only one row and a column and added this as a flow layout.

Later use UIEdgeInsets or draw a border of collection cell

like image 99
Rajan Maheshwari Avatar answered Sep 27 '22 15:09

Rajan Maheshwari