- Notifications
You must be signed in to change notification settings - Fork58
Reusable GridView with excellent performance and customization that can be time table, spreadsheet, paging and more.
License
KyoheiG3/GridView
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
GridView can tile the view while reusing it. It has an API like UIKit that works fast. Even when device rotates it smoothly relayout.
- Scroll like paging
- Scroll infinitely
- Scale the view
- Call API like the
UITableView
- Swift 5.0
- iOS 9.0 or later
Add the following to yourPodfile
:
pod"G3GridView"
⚠️ WARNING : If you want to install fromCocoaPods
, must addG3GridView
to Podfile because there is aGridView
different from thisGridView
.
Add the following to yourCartfile
:
github"KyoheiG3/GridView"
GridView can scroll in any direction while reusing Cell likeUITableView
. Also it is basedUIScrollView
and paging and scaling are possible. If necessary, it is possible to repeat the left and right scroll infinitely.
GridView is oneUIScrollView
, 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.
You can use it like theUITableView
APIs. However, there is concept ofColumn
. The following functions are delegate APIs of 'GridView'.
func gridView(_ gridView:GridView, numberOfRowsInColumn column:Int)-> Intfunc gridView(_ gridView:GridView, cellForRowAt indexPath:IndexPath)-> GridViewCell@objc optionalfunc numberOfColumns(in gridView:GridView)->Int
You can see that must return the count.
This project is including two examples that is timetable and paging. Those can change on Interface Builder for following:
Try the two examples.
timetable | paging |
---|---|
![]() | ![]() |
A horizontal loop is possible.
openvarisInfinitable:Bool
- Default is
true
. - Set
false
if you don't need to loop of view.
gridView.isInfinitable=true
Content is done relayout rather than scaling like 'UIScrollView'.
openvarminimumScale:ScaleopenvarmaximumScale:Scale
- Default for x and y are 1.
- Set the vertical and horizontal scales.
publicvarcurrentScale:Scale{get}
- Get current vertical and horizontal scales.
gridView.minimumScale=Scale(x:0.5, y:0.5)gridView.maximumScale=Scale(x:1.5, y:1.5)
It is possible to decide the placement of Cell at relayout.
openvarlayoutWithoutFillForCell:Bool
- Default is
false
. - Set
true
if need to improved view layout performance.
false | true |
---|---|
![]() | ![]() |
gridView.layoutWithoutFillForCell=true
IfisInfinitable
is true,contentOffset
depends on the content size including size to loop. It is possible to take content offset that actually visible.
openvaractualContentOffset:CGPoint{get}
Set the delegate destination. This delegate property isUIScrollViewDelegate
but, actually set theGridViewDelegate
.
weak open var dataSource: GridViewDataSource?open var delegate: UIScrollViewDelegate?
Get the view state.
publicfunc visibleCells<T>()->[T]publicfunc cellForRow(at indexPath:IndexPath)->GridViewCell?publicfunc rectForRow(at indexPath:IndexPath)->CGRectpublicfunc indexPathsForSelectedRows()->[IndexPath]publicfunc indexPathForRow(at position:CGPoint)->IndexPath
Operate the view.
publicfunc contentScale(_ scale:CGFloat)publicfunc reloadData()publicfunc invalidateContentSize()publicfunc invalidateLayout(horizontally:Bool= default)publicfunc deselectRow(at indexPath:IndexPath)override openfunc setContentOffset(_ contentOffset:CGPoint, animated:Bool)publicfunc scrollToRow(at indexPath:IndexPath, at scrollPosition:GridViewScrollPosition= default, animated:Bool= default)
Under the MIT license. SeeLICENSE file for details.
About
Reusable GridView with excellent performance and customization that can be time table, spreadsheet, paging and more.