UICollectionView and cell delimiters? Is this something that needs to be addressed with additional looks? Decor? Inside the cell itself?

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

Between each UICollectionViewCell I want to have a dividing line similar to a UITableView separator. (No, I cannot use the UITableView for this purpose for other reasons.)

How am I supposed to do this? Just add 1px high UIView to each cell? Use extra view? Use "decoration"? I'm lost, and no textbooks seem to indicate what will be best here.

It seems ridiculous to need to override the full UICollectionViewLayout to have some rows, but throwing a row in each cell seems messy. What should I do?

+5
source share
2 answers

I think the problem is with the 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 it as a stream layout. Once I did a slideshow with only one row and column and added this as a flow diagram.

Use UIEdgeInsets later or draw a collection cell border

+2
source

Apples Collection Programming Guide for iOS says (with my emphasis):

Decorations are visual decorations that enhance the look of collections. Unlike cells and additional views, decor views provide only visual content and therefore are independent of the data source. You can use them to create custom backgrounds, fill in the spaces around the cells, or even hide the cells if you want.

Therefore, the decor should be ideal for dividers. Additional views are not suitable because the data source does not need to configure each separator.

However, if your requirements are not too strict, adding separators to cells may be easier to implement. Do you need to hide the delimiter before the first or after the last element? If this is not important, you can add separators to the cells and do it in a few minutes.

Update:. I found insertion and deletion animations when using decorative representations, since the delimiters did not work well, so it is not recommended to use decorations if you need animated updates.

+2
source

All Articles