Coder Social home page Coder Social logo

kyoheig3 / gridview Goto Github PK

View Code? Open in Web Editor NEW
853.0 21.0 59.0 184 KB

Reusable GridView with excellent performance and customization that can be time table, spreadsheet, paging and more.

License: MIT License

Swift 99.19% Objective-C 0.45% Ruby 0.36%
gridview grid-layout timetable spreadsheet ios swift

gridview's Introduction

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.

timetable timetable

You Can

  • Scroll like paging
  • Scroll infinitely
  • Scale the view
  • Call API like the UITableView

Requirements

  • Swift 5.0
  • iOS 9.0 or later

How to Install

CocoaPods

Add the following to your Podfile:

pod "G3GridView"

โš ๏ธ 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.

timetable paging
timetable paging

Usage

Variables

Infinite Loop

A horizontal loop is possible.

open var isInfinitable: Bool
  • Default is true.
  • Set false if you don't need to loop of view.

loop

gridView.isInfinitable = true

Scaling

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

open var minimumScale: Scale
open var maximumScale: Scale
  • Default for x and y are 1.
  • Set the vertical and horizontal scales.
public var currentScale: Scale { get }
  • Get current vertical and horizontal scales.

scaling

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
  • Default is false.
  • Set true if need to improved view layout performance.
false true
false true
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.

gridview's People

Contributors

akkyie avatar kyoheig3 avatar nonchalant avatar pokhachevskiy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gridview's Issues

a bit difficult for the sample

I'm new to Swift, but I don't know how to use samplecode. I don't know whether it's possible to give an example in a simpler way.
thx all !

Ability to reload datasource without calling reloadData

Hello!
Thanks for nice implementation of reusable collection on pure scrollview.
Now I'm using gridview for unlimited horizontal feed of cards.
The question is:
How can I update datasource without call reloadData?
For better UX I need to update datasource without reloading current visible cells.
If you have any suggestions how to do it, please answer here:)

Can GridView be used as a EPG viewer?

Dear friend:
First of all, my congratulations for the excelent work.
I wish to ask a question:
Can GridView be used to show an EPG (Electronic Program Viewer)?
The date/time should be in top and the channel names in left 9using some kind of custom cell layout).
Is this possible?

Thanks for your help.

tvOS

Hi there,
I'm relative new to swift.
This project is super great. I want to use it as a reference for my tvOS app.
However the Podfile isn't working for tvOS.

Is there a way I can still be able to use it for tvOS?

Value of type error

Hi.
I am trying to run GridViewExample. When I try to run it, swift compile error appears in the function visibleCells it says has no member 'compactMap'. I am using Xcode 9.2.

public func visibleCells() -> [T] {
return currentInfo.visibleObject().values.compactMap { $0.view as? T }
}

Thank you.
screen shot 2018-11-15 at 11 24 18 am

Please Help !

Dear author,
My project USES your library
But I find that the Reload of TableView causes the screen to be delayed
MainQueue does too much at the same time, right?
And this condition is in Sample, I wonder if you can optimize it?
I can pay for this optimization! Or Donate!

Append

How can I append column & row?

Can not run project

Dear admin,

I can not run this project, error occurs when executing this line
timeTableView.register(TimeTableGridViewCell.nib, forCellWithReuseIdentifier: "TimeTableGridViewCell") channelListView.register(ChannelListGridViewCell.nib, forCellWithReuseIdentifier: "ChannelListGridViewCell") dateTimeView.register(DateTimeGridViewCell.nib, forCellWithReuseIdentifier: "DateTimeGridViewCell")

Could you please help me resolve this issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.