• Stars
    star
    677
  • Rank 66,694 (Top 2 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ“Custom layouts for UICollectionView with examples [iOS 12+].

uicollectionview-layouts-kit Awesome

Platform Language CustomLayouts Last Commit NLOC Contributors Repo Size License

If you like the project, please give it a star โญ It will show the creator your appreciation and help others to discover the repo.

โœ๏ธ About

๐Ÿ“ A set of custom layouts for UICollectionView with examples. All the layouts support both portrait and landscape UI orientations as well as support for all iOS-related size classes (iPhone & iPad).

โš ๏ธ Warning

The assets used in this project were taken from the Web. Do not use them for commertial purposes and proprietary projects. They are used just for demostration only.

๐Ÿ— Setup

In order to add layouts to your project, simply copy-paste corresponding Layout file (each of the targets has folder called Layout that contains all the related sources). There is no point in adding any dependency manager, since each custom UICollectionViewLayout can be more easily added just by dropping the corresponding layout source file into your project.

โœˆ๏ธ Usage

The next step is to either programmatically or via Storyboard/Nib file connect the layout and override the default one.

Programmatic Setup

If you choose programmatic approach, all you need to do is to set the instance of a layout using the following scheme:

...
let verticalSnapCollectionFlowLayout = VerticalSnapCollectionFlowLayout()
// Use custom properties that are available for each layout
verticalSnapCollectionFlowLayout.minLineSpacing = 30
verticalSnapCollectionFlowLayout.spacingMultiplier = 8

collectionView.collectionViewLayout = verticalSnapCollectionFlowLayout

// or 

collectionView.setCollectionViewLayout(verticalSnapCollectionFlowLayout, animated: true)

Storyboard/Nib Setup

Setting up the layouts via Storyboard/Nib is very easy as well. All you need to do is the following:

  1. Find your Collection View in Xcode's visual editor
  2. Select it
  3. Open Attributes Inspector
  4. Find and change UI menu called Layout to Custom
  5. Set the class to the one that you wish to use

In your view controller you need to provide a valid reference to the UIViewController from Storyboard/Nib file where you overriden the default layout class.

For cases when you need to tell your custom layout what class is going to delegate the layout handling, use the following code:

...
if let layout = collectionView?.collectionViewLayout as? PinterestLayout {
    layout.delegate = self
}
...

For cases when you simply need to change properties for custom layouts that were set via visual editor, use the following code:

...
if let layout = collectionView?.collectionViewLayout as? InstagridLayout {
    layout.itemSpacing = 10
    layout.fixedDivisionCount = 4
    layout.scrollDirection = .vertical
}
...

If you use Storyboard/Nib approach, consider creating an IBOutlet to the custom layout and directly set it up, instead of casting layout using the collection view reference:

...
@IBOutlet weak var instagridLayout: InstagridLayout!

override func viewDidLoad() {
    super.viewDidLoad()
    
    // InstagridLyout setup
    instagridLayout.delegate = self
    instagridLayout.itemSpacing = 10
    instagridLayout.fixedDivisionCount = 4
    instagridLayout.scrollDirection = .vertical
}
...

๐Ÿ“š Contents

Please wait while the .gif files are loading (each of them is around 10Mb)

Safari iPhone

It's a custom layout that mimics UICollectionView layout that can be seen on iPhones in portrait orientation. The layout only supports portrait orientation, but can be adjusted for landscape orientation and even for n-column layout, that can be used, for example on wider screens, such as iPads.

  • Perspective transformation that reveal cell's content while scrolling up and down
  • Automatically adjusts contents to fit the current screen
  • Portrait orientation
  • Only for iPhones
  • Adjustable: various properties can be changed
  • Scalable: can be adopted to support iPad and various, sophisticated perspective transformation while scrolling

Stack

Is a custom layout that places the collection view items on top of each other - just as a stack of books on a table, observed from the top-to-bottom perspective.

  • Snapping behavior when swiping between items
  • Automatically adjusts the cell sizes
  • Portrait & landscape orientations
  • Customizable

Snap

Is a custom flow layout that adds snapping behavior to single column collection view. Landscape layout changes the number of columns to two - in order to more ergonomically fill in the horizontal space.

  • Snapping behavior when scrolling
  • Automatically adjusts the cell sizes
  • Supports both scrolling directions e.g. .vertical and .horizontal
  • Portrait & landscape orientations, with customizable horizontalOrientationDevider property, which adds an additional row of in the collection view layout
  • Has customazable properties

Vertical Scrolling

Horizontal Scrolling

Pinterest

Is a custom layout that mimics Pinterest layout. Can be customized with a variable number of rows and custom cells.

  • Automatically adjusts the cell sizes
  • Supports both scrolling directions e.g. .vertical and .horizontal
  • Portrait & landscape orientations
  • Has customazable properties

Spinner

Is a custom layout that places collection view cells in a circular fashion with a snapping behavior. The spinning circle radius, cell size and cell decoration view can be customized. Supports both landscape and portrait layouts.

  • Snapping behavior
  • Automatically adjusts the cell sizes
  • Supports both scrolling directions e.g. .vertical and .horizontal
  • Portrait & landscape orientations
  • Has customazable properties

Instagrid

Is a custom layout similar to Instagram's feed layout. Has several customization points and a delegate protocol for cell size runtime customization.

  • Snapping behavior
  • Automatically adjusts the cell sizes
  • Supports both scrolling directions e.g. .vertical and .horizontal
  • Portrait & landscape orientations
  • Has customazable properties

Horizontal

Drawing

Vertical

๐Ÿคฉ Stargazers

Stargazers over time

๐Ÿ‘จโ€๐Ÿ’ป Author

Astemir Eleev

๐Ÿ”– Licence

The project is available under MIT Licence

More Repositories

1

ios-learning-materials

๐Ÿ“š Curated list of articles, tutorials and repos that may help you dig a little bit deeper into iOS [and Apple Platforms].
Swift
1,976
star
2

compositional-layouts-kit

๐Ÿ“ Advanced compositional layouts for UICollectionView [iOS 13+].
Swift
389
star
3

flappy-fly-bird

๐Ÿฆ Flappy Bird game reincarnation [GameplayKit, SpriteKit, iOS 12+].
Swift
331
star
4

swiftui-2048

๐ŸŽฒ Classic 2048 game [SwiftUI 3.0, iOS 15.0+, macOS 12.0+].
Swift
216
star
5

drawer-view

๐Ÿ“ค Custom UI component for iOS, replication of Apple's Apple Music player and Shortcutsโ€™ components view [Swift 5.0, iOS 12].
Swift
151
star
6

swift-design-patterns

๐Ÿš€ The ultimate collection of Software Design Patterns & Principles with examples [36/79 Patterns].
Swift
123
star
7

expandable-collection-view-kit

๐Ÿ—‚ Expandable, hierarchical, flexible, declarative UICollectionView with diffable data sources & SwiftUI-like tree items builder [Swift 5.1, iOS & iPadOS 13].
Swift
115
star
8

spritekit-water-node

๐ŸŒŠ Custom SpriteKit node that allows to simulate 2D water with respect to physics. The app demonstrates Flocking behaviour using GameplayKit, key-frame animation and custom fragment shader chaining (GLSL) ๐Ÿคฏ
Swift
93
star
9

ios-spritekit-shader-sandbox

๐Ÿ‘พ Collection of custom effects for SpriteKit implemented using GLSL/Metal shaders.
Swift
74
star
10

extensions-kit

๐Ÿ“ฆ Collection of Swift+Apple Frameworks extensions for speeding up software development [iOS & iPadOS].
Swift
71
star
11

tic-tac-toe

๐Ÿ•น iOS game - classic Tic Tac Toe with AI and state machines [Swift + SpriteKit + GameplayKit].
Swift
62
star
12

ios-scenekit-shadertoy

๐ŸŽฎ Easily add, changed and combine Vertex and Fragment shaders for SceneKit objects. Perfect tool for prototyping shaders in the context of SceneKit framework.
Swift
52
star
13

swift-algorithms-data-structs

๐Ÿ“’ Algorithms and Data Structures in Swift. The used approach attempts to fully utilize the Swift Standard Library and Protocol-Oriented paradigm.
Swift
49
star
14

soft-skills

๐ŸฆList of Soft Skills for software engineers/developers.
Markdown
39
star
15

grid-compositional-layout

๐Ÿงฒ Grid Compositional Layout is a SwiftUI 2.0 view that lays out the supplied views in a grid. Easily configurable and lazily retained [Swift 5.3, iOS 14.0+, iPadOS 14.0+, macOS 11.0(10.16)+]
Swift
39
star
16

skcomponents-kit

โš—๏ธ Collection of SpriteKit components for intermediate/advanced use cases.
Swift
36
star
17

sprite-liquids-ios-app

๐Ÿ’งDemonstrates a practical approach for liquid visualization using SpriteKit and CoreImage frameworks.
Objective-C
22
star
18

constraints-kit

๐Ÿ— Declarative, Chainable & Lightweight Auto Layout constraints framework for iOS.
Swift
21
star
19

hungry-wormy

๐Ÿ› iOS & macOS game - classic snake game [Swift + SpriteKit].
Swift
19
star
20

physics-vehicle

๐Ÿš— Physics-based 2D car behaviour and suspension demo [Swift, SpriteKit, iOS, macOS].
Swift
19
star
21

concurrency-kit

๐Ÿš„ Concurrency abstractions framework for Apple Platforms [Task, Atomic, Lock, Operation, etc.].
Swift
19
star
22

15-puzzle

๐Ÿงฉ iOS game - classic 15 Puzzle game [Swift + SpriteKit].
Swift
17
star
23

column-text-view-ui

๐Ÿ“„ Column Text View is an adaptive UI component that renders text in columns, horizontally [iOS 12, UIKit, TextKit, SwiftUI].
Swift
11
star
24

voice-recognition-ios-demo

๐ŸŽค Small app for voice recognition feature introduced in iOS 10.0 SDK.
Swift
9
star
25

metal-path-ios-app

๐Ÿค– Sandbox that holds various Metal API related scenes, from very fundamental to advanced developments
Swift
9
star
26

swift-functional

๐Ÿง  Articles and notes about functional programming in Swift.
Swift
7
star
27

message-view-ui

โœ‰๏ธ Easy to use HUD component for iOS [activity report, success or warning messages, etc.]
Swift
6
star
28

safari-tabs-extracter

๐Ÿ“— A script that extracts all tabs (as URLs) from Safari and saves them in a Markdown file [AppleScript]
AppleScript
6
star
29

jToolkit

โ˜•๏ธ Collection of various utilities, classes and shaders for Java + OpenGL + GLSL development.
Java
5
star
30

MTLTextureView

๐Ÿ–ผ๏ธ Render images as Metal textures.
Swift
4
star
31

device-kit

๐Ÿ“ฑGet extended information about an iOS/iPadOS device.
Swift
4
star
32

eleev.github.io

๐Ÿ’ผ Personal web page.
HTML
3
star
33

metal-particle-system-app

Particle system written on Metal shading language and Metal framework. ๐ŸŽŠ๐ŸŽ‰
Swift
2
star
34

jVirus

1
star