Home

Awesome

GridView

Build Status Carthage compatible Version License Platform

GridView can tile the view while reusing it. It has an API like UIKit that works fast. Even when device rotates it smoothly relayout.

<img alt="timetable" src="https://github.com/KyoheiG3/assets/blob/master/GridView/timetable_p.png" height="333"> <img alt="timetable" src="https://github.com/KyoheiG3/assets/blob/master/GridView/timetable_l.png" width="333">

Appetize's Demo

You Can

Requirements

How to Install

CocoaPods

Add the following to your Podfile:

pod "G3GridView"

:warning: WARNING : If you want to install from CocoaPods, must add G3GridView to Podfile because there is a GridView different from this GridView.

Carthage

Add the following to your Cartfile:

github "KyoheiG3/GridView"

Over View

GridView can scroll in any direction while reusing Cell like UITableView. Also it is based UIScrollView and paging and scaling are possible. If necessary, it is possible to repeat the left and right scroll infinitely.

GridView is one UIScrollView, but the range which Cell is viewed depends on Superview. Cell reuse is also done within the range which Superview is viewed, so its size is very important.

On the other hand, scaling and paging depend to position and size of GridView. 'bounds' is important for paging, 'frame' is important in scaling. The same is true for offset of content.

The following image is a visual explanation of the view hierarchy.

Hierarchy

You can use it like the UITableView APIs. However, there is concept of Column. The following functions are delegate APIs of 'GridView'.

func gridView(_ gridView: GridView, numberOfRowsInColumn column: Int) -> Int
func gridView(_ gridView: GridView, cellForRowAt indexPath: IndexPath) -> GridViewCell

@objc optional func numberOfColumns(in gridView: GridView) -> Int

You can see that must return the count.

Examples

This project is including two examples that is timetable and paging. Those can change on Interface Builder for following:

Example

Try the two examples.

timetablepaging
<img alt="timetable" src="https://github.com/KyoheiG3/assets/blob/master/GridView/timetable.gif" width="333"><img alt="paging" src="https://github.com/KyoheiG3/assets/blob/master/GridView/paging.gif" width="333">

Usage

Variables

Infinite Loop

A horizontal loop is possible.

open var isInfinitable: Bool
<img alt="loop" src="https://github.com/KyoheiG3/assets/blob/master/GridView/loop.gif" height="333">
gridView.isInfinitable = true

Scaling

Content is done relayout rather than scaling like 'UIScrollView'.

open var minimumScale: Scale
open var maximumScale: Scale
public var currentScale: Scale { get }
<img alt="scaling" src="https://github.com/KyoheiG3/assets/blob/master/GridView/scaling.gif" height="333">
gridView.minimumScale = Scale(x: 0.5, y: 0.5)
gridView.maximumScale = Scale(x: 1.5, y: 1.5)

Fill for Cell

It is possible to decide the placement of Cell at relayout.

open var layoutWithoutFillForCell: Bool
falsetrue
<img alt="false" src="https://github.com/KyoheiG3/assets/blob/master/GridView/false.gif" width="333"><img alt="true" src="https://github.com/KyoheiG3/assets/blob/master/GridView/true.gif" width="333">
gridView.layoutWithoutFillForCell = true

Content Offset

If isInfinitable is true, contentOffset depends on the content size including size to loop. It is possible to take content offset that actually visible.

open var actualContentOffset: CGPoint { get }

Delegate

Set the delegate destination. This delegate property is UIScrollViewDelegate but, actually set the GridViewDelegate.

weak open var dataSource: GridViewDataSource?
open var delegate: UIScrollViewDelegate?

Functions

State

Get the view state.

public func visibleCells<T>() -> [T]
public func cellForRow(at indexPath: IndexPath) -> GridViewCell?
public func rectForRow(at indexPath: IndexPath) -> CGRect
public func indexPathsForSelectedRows() -> [IndexPath]
public func indexPathForRow(at position: CGPoint) -> IndexPath

Operation

Operate the view.

public func contentScale(_ scale: CGFloat)
public func reloadData()
public func invalidateContentSize()
public func invalidateLayout(horizontally: Bool = default)
public func deselectRow(at indexPath: IndexPath)
override open func setContentOffset(_ contentOffset: CGPoint, animated: Bool)
public func scrollToRow(at indexPath: IndexPath, at scrollPosition: GridViewScrollPosition = default, animated: Bool = default)

LICENSE

Under the MIT license. See LICENSE file for details.