Giter Club home page Giter Club logo

reorderablegridview-swift's Introduction

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.

reorderablegridview-swift's People

Contributors

cemolcay avatar

Watchers

David Walsh avatar James Cloos avatar

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.