Skip to content

snoozemoose/CircularCollectionView

 
 

Repository files navigation

Swift UICollectionView with circle arrangement of cells

This is an demonstration of using custom UICollectionViewLayout to lay out a series of cells in a circle in Swift.

See WWDC 2012 video Advanced Collection Views and Building Custom Layouts, which shows an example of precisely this, using a custom circular layout (about 40+ minutes into the video). That was written in Objective-C. This is a Swift 3 implementation.

This yields:

circular layout

Alternatively, if you want to see these circular views laid out so they're touching each other in a grid layout, see the alternating-grid branch of this repo.

But the basic idea is to create a custom UICollectionViewLayout that implements:

  • collectionViewContentSize;
  • layoutAttributesForItem(at indexPath:); and
  • layoutAttributesForElements(in rect:).

I created a @IBDesignable view for the circular view, but that is not critical to the question at hand, namely custom UICollectionViewLayout to lay out a series of cells in a circle.

This is not intended as an end-user library, but this is for illustrative purposes only.

See http://stackoverflow.com/a/41839446/1271826.

Developed in Swift 3 on Xcode 8.2.1 for iOS 10. But, the basic ideas are equally applicable for different versions of Swift and/or Objective-C.

License

Copyright © 2017 Robert Ryan. All rights reserved.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

--

24 January 2017

About

Swift `UICollectionView` with circle of cells

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 93.7%
  • Objective-C 6.3%