Git Product home page Git Product logo

touchdraw's Introduction

TouchDraw

Join the chat at https://gitter.im/dehli/TouchDraw

The TouchDraw module allows you to use the TouchDrawView class. This is a subclass of UIView which allows you to draw pictures with your finger.

Installation

The easiest way to include TouchDraw is by using CocoaPods and adding the following to your Podfile.

use_frameworks!
pod 'TouchDraw', '~> 2.1'

If you're not using CocoaPods, you can add the TouchDrawView.swift file to your project.

Usage

You can either programmatically add the TouchDrawView or add it using storyboards.

Storyboards

If using storyboards, you must add a UIView to your storyboard. Give it the TouchDrawView class, and TouchDraw module.

Storyboard class

Code

If programmatically adding the view, you can use the init(frame: CGRect) method to create a new instance of TouchDrawView. You must make sure to write import TouchDraw at the top of the class, and also set isUserInteractionEnabled to true.

Customizing

When customizing the TouchDrawView you can setting its delegate. The container can conform to parts of TouchDrawViewDelegate, which has the following functions:

func undoEnabled() {
    // triggered when undo is enabled
    // (only if it was previously disabled)
}
func undoDisabled() {
    // triggered when undo is disabled
    // (only if it previously enabled)
}
func redoEnabled() {
    // triggered when redo is enabled
    // (only if it was previously disabled)
}
func redoDisabled() {
    // triggered when redo is disabled
    // (only if it previously enabled)
}
func clearEnabled() {
    // triggered when clear is enabled
    // (only if it was previously disabled)
}
func clearDisabled() {
    // triggered when clear is disabled
    // (only if it previously enabled)
}

The TouchDrawView exposes the following methods:

  • exportDrawing() -> UIImage
    • Exports a UIImage version of the drawing.
  • clearDrawing()
    • Clears the TouchDrawView.
  • undo()
    • Undo the last stroke.
  • redo()
    • Redo what was undone.
  • setColor(color: UIColor?)
    • Sets the color of future strokes, if you pass nil you will be erasing.
  • setWidth(width: CGFloat)
    • Sets the width of future strokes.
  • importStack(stack: [Stroke])
    • Set the TouchDrawView to have certain strokes (usually will be used in conjunction with exportStack().
  • exportStack() -> [Stroke]
    • Exports the strokes from a TouchDrawView so they can be imported later.

Demo

If you'd like to see this library in action, you can download the entire repository and open Demo/TouchDrawDemo.xcworkspace.

Demo/TouchDrawDemo/ViewController.swift is where most of its functionality is demonstrated.

Demo Screenshot

License

This package has the MIT license, which can be found here: LICENSE.

Code of Conduct

Please make sure to follow the Code of Conduct when you interact with this project. Thanks!

touchdraw's People

Contributors

dehli avatar sirnacnud avatar ricsantos avatar rivera-ernesto avatar igorkulman avatar mkoorn avatar gitter-badger avatar codyaweber avatar fl034 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.