All Projects → mischa-hildebrand → Alignedcollectionviewflowlayout

mischa-hildebrand / Alignedcollectionviewflowlayout

Licence: mit
A collection view layout that gives you control over the horizontal and vertical alignment of the cells.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Alignedcollectionviewflowlayout

Collectionviewpaginglayout
a simple but highly customizable paging layout for UICollectionView.
Stars: ✭ 947 (+26.1%)
Mutual labels:  uikit, uicollectionviewlayout, uicollectionview
Collectionviewslantedlayout
A CollectionView Layout displaying a slanted cells
Stars: ✭ 2,029 (+170.17%)
Mutual labels:  uikit, uicollectionviewlayout, uicollectionview
Uicollectionview Layouts Kit
📐 A set of custom layouts for UICollectionView with examples [Swift 5.3, iOS 12].
Stars: ✭ 410 (-45.41%)
Mutual labels:  uikit, uicollectionviewlayout, uicollectionview
Squaremosaiclayout
An extandable mosaic UICollectionViewLayout with a focus on extremely flexible customizations 🔶
Stars: ✭ 243 (-67.64%)
Mutual labels:  uikit, uicollectionviewlayout, uicollectionview
Pagingkit
PagingKit provides customizable menu UI. It has more flexible layout and design than the other libraries.
Stars: ✭ 1,030 (+37.15%)
Mutual labels:  uikit, uicollectionviewlayout, uicollectionview
JQCollectionViewAlignLayout
A custom layout object based on flow layout. Added supports for horizontal, vertical alignment and RTL direction of collection view items.(available for both UICollectionView and NSCollectionView)
Stars: ✭ 69 (-90.81%)
Mutual labels:  uicollectionview, alignment, uicollectionviewlayout
ScrollAnimationShowcase
[ING] - UIScrollViewやUICollectionViewの特性を活用した表現サンプル
Stars: ✭ 15 (-98%)
Mutual labels:  uicollectionview, uicollectionviewlayout
iOSEasyList
A data-driven UICollectionView and UITableView framework for building fast and flexible lists
Stars: ✭ 29 (-96.14%)
Mutual labels:  uicollectionview, uicollectionviewlayout
Uicollectionviewflexlayout
A drop-in replacement for UICollectionViewFlowLayout
Stars: ✭ 277 (-63.12%)
Mutual labels:  uicollectionviewlayout, uicollectionview
Wslwaterflowlayout
功能描述:WSLWaterFlowLayout 是在继承于UICollectionViewLayout的基础上封装的控件, 目前支持竖向瀑布流(item等宽不等高、支持头脚视图)、水平瀑布流(item等高不等宽 不支持头脚视图)、竖向瀑布流( item等高不等宽、支持头脚视图)、栅格布局瀑布流 4种样式的瀑布流布局。
Stars: ✭ 308 (-58.99%)
Mutual labels:  uicollectionviewlayout, uicollectionview
ScaledCenterCarousel
A carousel-based layout for UICollectionView with scaled center item.
Stars: ✭ 16 (-97.87%)
Mutual labels:  uicollectionview, uicollectionviewlayout
Swiftdatatables
A Swift Data Table package, display grid-like data sets in a nicely formatted table for iOS. Subclassing UICollectionView that allows ordering, and searching with extensible options.
Stars: ✭ 287 (-61.78%)
Mutual labels:  uicollectionviewlayout, uicollectionview
Compositional Layouts Kit
📏 A set of advanced compositional layouts for UICollectionView with examples [Swift 5.3, iOS 13].
Stars: ✭ 317 (-57.79%)
Mutual labels:  uikit, uicollectionviewlayout
TinderUISamples
[ING] - TinderのようなUIを様々な実装で実現してみる
Stars: ✭ 30 (-96.01%)
Mutual labels:  uicollectionview, uikit
SectionKit
♻️ Reusable sections for UICollectionView
Stars: ✭ 47 (-93.74%)
Mutual labels:  uicollectionview, uikit
Swiftspreadsheet
Spreadsheet CollectionViewLayout in Swift. Fully customizable. 🔶
Stars: ✭ 590 (-21.44%)
Mutual labels:  uicollectionviewlayout, uicollectionview
Transfiguration
Mystical way to transform data into reusable view in Swift
Stars: ✭ 14 (-98.14%)
Mutual labels:  uicollectionview, uicollectionviewlayout
Wlemptystate
WLEmptyState is an iOS based component that lets you customize the view when the dataset of a UITableView or a UICollectionView is empty. We created a sample project with the WLEmptyState component to show how you can use it.
Stars: ✭ 305 (-59.39%)
Mutual labels:  uikit, uicollectionview
Bouncylayout
Make. It. Bounce.
Stars: ✭ 4,035 (+437.28%)
Mutual labels:  uicollectionviewlayout, uicollectionview
Owl
A declarative type-safe framework for building fast and flexible lists with UITableViews & UICollectionViews
Stars: ✭ 423 (-43.68%)
Mutual labels:  uikit, uicollectionview

AlignedCollectionViewFlowLayout

Version CocoaPods License Platform

A collection view layout that gives you control over the horizontal and vertical alignment of the cells. You can use it to align the cells like words in a left- or right-aligned text and you can specify how the cells are vertically aligned within their rows.

Other than that, the layout behaves exactly like Apple's UICollectionViewFlowLayout. (It's a subclass.)

ℹ️ Important:

AlignedCollectionViewFlowLayout was developed with a "tag view" in mind, i.e. a collection view that displays a limited number of items with a relatively simple layout. It works perfectly for this use case. While it also does its job for a large number of items and more complex cell layouts scrolling might become laggy in this case. This is due to the fact the layout needs to recursively obtain layout attributes from its superclass and cannot be avoided. If you experience unacceptable lagginess please consider other alternatives.

Available Alignment Options

You can use any combination of horizontal and vertical alignment to achieve your desired layout.

Horizontal Alignment:

  • horizontalAlignment = .left

Example layout for horizontalAlignment = .left

  • horizontalAlignment = .right

Example layout for horizontalAlignment = .right

  • horizontalAlignment = .justified

Example layout for horizontalAlignment = .justified

Vertical Alignment:

  • verticalAlignment = .top

Example layout for verticalAlignment = .top

  • verticalAlignment = .center

Example layout for verticalAlignment = .center

  • verticalAlignment = .bottom

Example layout for verticalAlignment = .bottom

Installation

With CocoaPods:

AlignedCollectionViewFlowLayout is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "AlignedCollectionViewFlowLayout"

Manual installation:

Just add the file AlignedCollectionViewFlowLayout.swift to your Xcode project and you're ready to go.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Usage

Setup in Interface Builder

  1. You have a collection view in Interface Builder and setup its data source appropriately. Run the app and make sure everything works as expected (except the cell alignment).

  2. In the Document Outline, select the collection view layout object.

    Screenshot of the Flow Layout object in Interface Builder

  3. In the Identity Inspector, set the layout object's custom class to AlignedCollectionViewFlowLayout.

    Screenshot: How to set a custom class for the layout object in Interface Builder

  4. Add and customize the following code to your view controller's viewDidLoad() method:

    let alignedFlowLayout = collectionView?.collectionViewLayout as? AlignedCollectionViewFlowLayout
    alignedFlowLayout?.horizontalAlignment = .left
    alignedFlowLayout?.verticalAlignment = .top
    

    If you omit any of the last two lines the default alignment will be used (horizontally justified, vertically centered).

    💡 Pro Tip: Instead of type-casting the layout as shown above you can also drag an outlet from the collection view layout object to your view controller.

Setup in code

  1. Create a new AlignedCollectionViewFlowLayout object and specify the alignment you want:

    let alignedFlowLayout = AlignedCollectionViewFlowLayout(horizontalAlignment: .left, verticalAlignment: .top)
    
  2. Either create a new collection view object and and initialize it with alignedFlowLayout:

    let collectionView = UICollectionView(frame: bounds, collectionViewLayout: alignedFlowLayout)
    

    or assign alignedFlowLayout to the collectionViewLayout property of an existing collection view:

    yourExistingCollectionView.collectionViewLayout = alignedFlowLayout
    
  3. Implement your collection view's data source.

  4. Run the app.


Additional configuration

For the left and right alignment AlignedCollectionViewFlowLayout distributes the cells horizontally with a constant spacing which is the same for all rows. You can control the spacing with the minimumInteritemSpacing property.

alignedFlowLayout.minimumInteritemSpacing = 10

Despite its name (which originates from its superclass UICollectionViewFlowLayout) this property doesn't describe a minimum spacing but the exact spacing between the cells.

The vertical spacing between the lines works exactly as in UICollectionViewFlowLayout:

alignedFlowLayout.minimumLineSpacing = 10

Enjoy! 😎

Author

Mischa Hildebrand, [email protected]

Twitter Follow GitHub followers

License

AlignedCollectionViewFlowLayout is available under the MIT license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].