-1

Given that using the minimumInteritemSpacing / minimumLineSpacing settings on an iOS collection view creates a space rather than a solid border between cells, how can we style a solid border of consistent width around each cell in a collection view grid with a seperate colour applied as the background to the main collection view (so that after the border of the last cell a different background colour is visible) using these methods?

This is the best example of a solution I have seen so far but it is for objective C only rather than swift 3. The author also outlines the shortcomings of a couple of approaches I have already tried:

UICollectionView custom line separators

As an additional note the grid contains items of varying dimensions as illustrated here:

github.com/Antondomashnev/ADMozaicCollectionViewLayout

Edit - Here is an image of the effect I'm trying to achieve:

Custom CollectionView

It also highlights the problem that whil]1st the blue borders are most easily created using minimumInteritemSpacing / minimumLineSpacing the spaces created (whilst accurate and evenly spaced) just show the colour of the background view beneath the cells so you are left with one solid colour as opposed to the blue and yellow combination shown in the image.

Tjor
  • 1
  • 2
  • This is confusing... Are the links you posted giving you the results you want? – DonMag Jun 07 '17 at 20:27
  • Apologies, I could have been clearer. The first link is to the closest question I could find that relates to the problem but the solution is quite old and is implemented in Objective C rather than Swift 3. The second link is to the framework I'm using to create the collection view grid but the problem is that I'm unable to create a consistent 10px border around each cell in such a way that I can have a different colour as the main background colour to the collection view because the way creating the border works is to create a space between the cells that shows the background colour beneath it – Tjor Jun 07 '17 at 22:19
  • OK - best bet then is to "mock up" an image showing how you *want* it to look. Also, you say you're using the ADMozaic framework... but if it doesn't give you the look you want, does it have some other features that would make you want to keep using it? Or is that just the closest you've gotten, but you'd just as soon use something else? – DonMag Jun 07 '17 at 22:33
  • Thanks DonMag, I've updated my answer accordingly with a link to a diagram of the desired result - I don't have enough reputation points yet to embed the image directly. I'd like to stick with ADMozaic if possible as it does a great job of efficiently implementing the type of grid view I'm after in swift with the only downside being the complexity around cell spacing but I think there are still ways to have the best of both worlds at the moment – Tjor Jun 07 '17 at 23:01

1 Answers1

0

I was able to get the result I wanted by setting a minimumLineSpacing and minimumInterimItemSpacing value of 0 to group the cells together and dynamically adding / removing borders as CALayers using krotov's answer here: UIView bottom border?

Tjor
  • 1
  • 2