Latest0.2
Homepagehttps://github.com/cemolcay/ReorderableGridView-Swift
LicenseMIT
Platformsios 8.0, requires ARC
Authors

ReorderableGridView-Swift

reorderable grid view solution implemented with swift.
its UIScrollView subclass, its not a collection view layout.
automatically sets horizontal item spacing by item widths. so items must be fixed-width.
also sets automatically its content size.
if you call gridView?.invalidateLayout() after orientation changed, it will lays out the grid by new orientation.

Demo

alt tag

Usage

copy & paste the ReorderableGridView.swift into your project.

  gridView = ReorderableGridView(frame: self.view.frame, itemWidth: 180, verticalPadding: 20)
  self.view.addSubview(gridView!)

Grid view ready !

now you can add it ReorderableView instances

  let itemView = ReorderableView (x: 0, y: 0, w: 180, h: 250)
  ...
  gridView?.addReorderableView(itemView)

  // or
  let pos = GridPosition (x: 0, y: 1)
  gridView?addReorderableView (itemView, gridPosition: pos)

or remove them

gridView?.removeReorderableViewAtGridPosition(GridPosition (x: 0, y: 0))

// or
gridView?.removeReorderableView (itemView)

Design Tip
View itself don’t have any margin padding.
It uses all frame width to calculate how many ReorderableViews can fit and
what should be their horizontal padding in a row.
Padding between columns (vertical padding) can be set in init method,
which is 10 by default.
You can have a container view and use something like
CGRectInset (containerView.frame, marginX, marginY)
when init grid with margin

Optional Values

  var reorderable : Bool = true
  var draggable : Bool = true
  var draggableDelegate: Draggable?

set them if you want your grid editable or not

Draggable Protocol

func didDragStartedForView (reorderableGridView: ReordableGridView, view: ReordableView)
func didDraggedView (reorderableGridView: ReordableGridView, view: ReordableView)
func didDragEndForView (reorderableGridView: ReordableGridView, view: ReordableView)

set gridView.draggableDelegate = self and implement Draggable protocol functions if you want to access info about dragging actions in grid.
This can be useful for multiple grid layouts.
Example included in second tab of demo.

Latest podspec

{
    "name": "ReorderableGridView",
    "version": "0.2",
    "summary": "reorderable grid view solution implemented with swift. its UIScrollView subclass, its not a collection view layout",
    "description": "  ReorderableGridView-Swiftn  =======================nn  reorderable grid view solution implemented with swift. 
n its UIScrollView subclass, its not a collection view layout.
n automatically sets horizontal item spacing by item widths. so items must be fixed-width.
n also sets automatically its content size.
n if you call `gridView?.invalidateLayout()` after orientation changed, it will lays out the grid by new orientation.nnn Demon ----nn ![alt tag](https://raw.githubusercontent.com/cemolcay/ReordableGridView-Swift/master/demo.gif)nn Usagen -----nn copy & paste the `ReorderableGridView.swift` into your project.
nn gridView = ReorderableGridView(frame: self.view.frame, itemWidth: 180, verticalPadding: 20)n self.view.addSubview(gridView!)nn Grid view ready !nn now you can add it `ReorderableView` instancesnn let itemView = ReorderableView (x: 0, y: 0, w: 180, h: 250)n ...n gridView?.addReorderableView(itemView)nn // orn let pos = GridPosition (x: 0, y: 1)n gridView?addReorderableView (itemView, gridPosition: pos)nnnn or remove themnn gridView?.removeReorderableViewAtGridPosition(GridPosition (x: 0, y: 0))nn // orn gridView?.removeReorderableView (itemView)nnn > **Design Tip**n > View itself don't have any margin padding.n > It uses all frame width to calculate how many `ReorderableView`s can fit andn > what should be their horizontal padding in a row.n > Padding between columns (vertical padding) can be set in init method,n > which is 10 by default.n > You can have a container view and use something liken > `CGRectInset (containerView.frame, marginX, marginY)`n > when init grid with marginnnnn Optional Valuesn ---------------nn var reorderable : Bool = truen var draggable : Bool = truen var draggableDelegate: Draggable?nn set them if you want your grid editable or notnn **Draggable Protocol**nn func didDragStartedForView (reorderableGridView: ReordableGridView, view: ReordableView)n func didDraggedView (reorderableGridView: ReordableGridView, view: ReordableView)n func didDragEndForView (reorderableGridView: ReordableGridView, view: ReordableView)nnn set `gridView.draggableDelegate = self` and implement `Draggable` protocol functions if you want to access info about dragging actions in grid.n This can be useful for multiple grid layouts.n Example included in second tab of demo.n", "homepage": "https://github.com/cemolcay/ReorderableGridView-Swift", "license": "MIT", "authors": { "Cem Olcay": "[email protected]" }, "platforms": { "ios": "8.0" }, "source": { "git": "https://github.com/cemolcay/ReorderableGridView-Swift.git", "tag": "v0.2" }, "source_files": "ReorderableGridView-Swift/ReorderableGridView.swift", "requires_arc": true }

Pin It on Pinterest

Share This