• Stars
    star
    224
  • Rank 177,792 (Top 4 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 8 years ago
  • Updated about 6 years ago

Reviews

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

Repository Details

ADMozaicCollectionViewLayout is yet another UICollectionViewLayout subclass that implements "brick", "mozaic" or Pinterest style layout.

ADMozaicCollectionViewLayout

Carthage compatible CocoaPods Compatible codebeat badge

What is it

ADMozaicCollectionViewLayout is yet another UICollectionViewLayout subclass that implements "brick" or "mozaic" layout.

example

Why do anybody need yet another one?

Because there are plenty of kind of the same layouts already:

But this project is pure swift implementation, so if you don't want to mess up objective-c code and swift you are on the right page. Also, as an advantage compares to another "mozaic" layout - you're not limited to predefined sizes of cells.

Usage

The idea behind this layout is to split UICollectionView bounds into some kind of "matrix". To do this ADMozaikCollectionViewLayout requires height for rows and width for columns in specific section.

/// Designated initializer for `ADMozaikLayout`
///
/// - Parameter delegate: delegate/datasource for the layout
public init(delegate: ADMozaikLayoutDelegate)

It requires the delegate object conforms to protocol ADMozaikLayoutDelegate. The first required method is to return the size of each item in layout:

/// Method should return `ADMozaikLayoutSize` for specific indexPath
///
/// - Parameter collectionView: collection view is using layout
/// - Parameter layout:         layout itself
/// - Parameter indexPath:      indexPath of item for the size it asks for
///
/// - Returns: `ADMozaikLayoutSize` struct object describes the size
func collectionView(_ collectionView: UICollectionView, mozaik layout: ADMozaikLayout, mozaikSizeForItemAt indexPath: IndexPath) -> ADMozaikLayoutSize

Where ADMozaikLayoutSize describes the size of each cell in terms of ADMozaikCollectionViewLayout

/**
 *  Defines the size of the layout item
 */
public struct ADMozaikLayoutSize {
  /// Columns number that item requires
  let columns: Int
  /// Rows number that item requires
  let rows: Int
}

The second method is to get the geometry information for each specific section of layout:

/// Method should return `ADMozaikLayoutSectionGeometryInfo` to describe specific section's geometry
///
/// - Parameters:
///   - collectionView: collection view is using layout
///   - layoyt:         layout itself
///   - section:        section to calculate geometry info for
///
/// - Returns: `ADMozaikLayoutSectionGeometryInfo` struct object describes the section's geometry
func collectonView(_ collectionView: UICollectionView, mozaik layoyt: ADMozaikLayout, geometryInfoFor section: ADMozaikLayoutSection) -> ADMozaikLayoutSectionGeometryInfo

Where ADMozaikLayoutSectionGeometryInfo describes the all geometry parameters of the section

/**
 *  Defines the layout's information
 */
public struct ADMozaikLayoutSectionGeometryInfo {
  /// array of `ADMozaikLayoutColumn` for the layout
  let columns: [ADMozaikLayoutColumn]

  /// height for each row in points
  let rowHeight: CGFloat

  /// minimum space between items
  let minimumInteritemSpacing: CGFloat

  /// minimum space between each row
  let minimumLineSpacing: CGFloat

  /// Insets for the section from top, left, right, bottom
  let sectionInset: UIEdgeInsets

  /// Height for header in section
  /// Width is currently limited to the collection view width
  let headerHeight: CGFloat

  /// Height for footer in section
  /// Width is currently limited to the collection view width
  let footerHeight: CGFloat
}

Content mode options

/// Method should return `ADMozaikLayoutSectionContentMode` to describe specific section's geometry
///
/// - Parameters:
///   - collectionView: collection view is using layout
///   - layout:         layout itself
///   - section:        section to return content mode for
///
/// - Returns: `ADMozaikLayoutSectionContentMode` enum describes the section's content mode and how to position cells
func collectonView(_ collectionView: UICollectionView, mozaik layout: ADMozaikLayout, contentModeFor section: ADMozaikLayoutSection) -> ADMozaikLayoutSectionContentMode

The contentMode option controls the way how the Mozaik layout is filled with items:

  1. fill - tries to fill vacant spaces with item;
  2. ordered - keeps order of the provided items, so empty space can appear in the collection view.

For the complete example please check the example project. Note that current example project is supposed to be run on iPhone 8 screen's size.

Install

CocoaPods

To integrate ADMozaicCollectionViewLayout into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'ADMozaicCollectionViewLayout', '~> 4.0'

Carthage

To integrate ADMozaicCollectionViewLayout into your Xcode project using Carthage, specify it in your Cartfile:

github "Antondomashnev/ADMozaicCollectionViewLayout" ~> 4.0

Run carthage update to build the framework and drag the built ADMozaikCollectionViewLayout.framework into your Xcode project.

Migration guide

License

ADMozaicCollectionViewLayout is available under the MIT license. See LICENSE for more information.

More Repositories

1

ADChromePullToRefresh

ADChromePullToRefresh
Swift
266
star
2

FBSnapshotsViewer

A mac os application that shows the failing snapshot tests from FBSnapshotTestCase
Swift
223
star
3

ADGraphView

Objective-C
209
star
4

ADPuzzleAnimation

Inspired by Fabric - Answers animation. Allows to "build" given view with pieces. Allows to "destroy" given view into pieces
Swift
124
star
5

ADTickerLabel

An objective-c UIView which provide a mechanism to show numbers with rolling effect, like in counter
Objective-C
115
star
6

UIViewController-ScrollingStatusBar

Category for UIViewController with UIScrollView to scroll statusBar along scrollView
Objective-C
94
star
7

ADDropDownMenuView

ADDropDownMenuView is an iOS navigation drop down style view
Objective-C
80
star
8

ADPopupView

ADPopupView
Objective-C
66
star
9

ADFBRequestDialogViewController

UIViewController with FBDialog to send Facebook app request inside
Objective-C
41
star
10

ADArrowButton

Flat arrow button.
Swift
22
star
11

UIScrollViewContentAccessors

Category for UIScrollView which make easier to access UIScrollView's content properties in iOS.
Objective-C
20
star
12

ADCustomTableView

Objective-C
17
star
13

danger-missed_localizable_strings

Don't let developers to forget about the app localization
Ruby
13
star
14

socket.IO-Blocks

Category on SocketIO to use block callbacks instead of delegate callbacks.
Objective-C
11
star
15

fastlane-plugin-remove-provisioning-profile

Remove provisioning profile from your local machine
Ruby
9
star
16

fastlane-plugin-download_github_release_asset

Fastlane plugin that downloads a GitHub release's asset
Ruby
2
star
17

nabokov

Move mobile localization boringness away from you 🏃
Ruby
2
star
18

iOS-Hackathon-Starter-Template

A boilerplate for objective-c iOS applications
Objective-C
2
star
19

ADContactsManager

Easy-to-use wrapper for both Contacts and AddressBook frameworks
Objective-C
2
star
20

jigit

Keep you JIRA issue statuses in sync with what you're doing actually
Ruby
1
star
21

CCPolygonNode

CCNode subclass to draw polygon with texture (adopt PRKit to cocos2d v3)
C++
1
star